Skip to content

Instantly share code, notes, and snippets.

@burubur
Created January 20, 2020 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save burubur/c6013240d5e57f9066e13a7bd4b9c97a to your computer and use it in GitHub Desktop.
Save burubur/c6013240d5e57f9066e13a7bd4b9c97a to your computer and use it in GitHub Desktop.
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