-
-
Save fuzzygroup/476481e96762dae981c3a020ae48a715 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'benchmark' | |
class BaseRuntime | |
def figlet | |
puts "starting service..." | |
end | |
end | |
class MainRuntime < BaseRuntime | |
def start | |
main_service = MainService.new | |
#main_service.read_config | |
main_service.read_config_once | |
p "done" | |
end | |
end | |
class MainService | |
def read_config_once | |
whitelisted_driver_ids = [] | |
Benchmark.bm do |x| | |
x.report { whitelisted_driver_ids = read_config_from_file } | |
end | |
p whitelisted_driver_ids | |
end | |
def read_config | |
n = 1000 | |
Benchmark.bm do |b| | |
b.report do | |
for i in 1..n do | |
whitelisted_driver_ids = read_config_from_file | |
end | |
end | |
b.report do | |
n.times do | |
whitelisted_driver_ids = read_config_from_file | |
end | |
end | |
b.report do | |
1.upto(n) do | |
whitelisted_driver_ids = read_config_from_file | |
end | |
end | |
end | |
end | |
private | |
def write_config | |
require 'json' | |
id = 940417010 | |
temp_data = [] | |
10000.times do | |
id = id + 1 | |
temp_data.push(id) | |
end | |
File.open("config_10000.json", "w") do |f| | |
f.write(temp_data.to_json) | |
end | |
end | |
def read_config_from_file | |
file_name = "config_10000.json" | |
file = File.open(file_name).read | |
driver_ids = Kernel.eval(file).to_a | |
driver_ids | |
end | |
end | |
runtime = MainRuntime.new | |
runtime.figlet | |
runtime.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment