benchmark-cars has been rewritten to perform WAY FASTER benchmarks.
parent
e801a5a8c9
commit
f888353ffb
|
@ -6,12 +6,12 @@ require "./db-cars.cr"
|
||||||
# ENV["CARNAME"] rescue "Corvet-#{(db_size/2).to_i}"
|
# ENV["CARNAME"] rescue "Corvet-#{(db_size/2).to_i}"
|
||||||
# ENV["CARCOLOR"] rescue "red"
|
# ENV["CARCOLOR"] rescue "red"
|
||||||
# ENV["CARKEYWORD"] rescue "spacious"
|
# ENV["CARKEYWORD"] rescue "spacious"
|
||||||
# ENV["DBSIZE"] rescue 40_000
|
# ENV["DBSIZE"] rescue 50_000
|
||||||
# ENV["DBSIZE_START"] rescue 5_000
|
# ENV["DBSIZE_START"] rescue 1_000
|
||||||
# ENV["DBSIZE_INCREMENT"] rescue 1_000
|
# ENV["DBSIZE_INCREMENT"] rescue 1_000
|
||||||
# ENV["REPORT_DIR"] rescue "results"
|
# ENV["REPORT_DIR"] rescue "results"
|
||||||
# ENV["NBRUN"] rescue 100
|
# ENV["NBRUN"] rescue 100
|
||||||
# ENV["INDEXESMAXIT"] rescue 5000
|
# ENV["MAXINDEXES"] rescue 5_000
|
||||||
|
|
||||||
class DODB::Storage(V)
|
class DODB::Storage(V)
|
||||||
def empty_db
|
def empty_db
|
||||||
|
@ -22,32 +22,58 @@ end
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
class_property report_dir = "results"
|
class_property report_dir = "results"
|
||||||
|
class_property max_indexes = 5_000
|
||||||
|
class_property nb_run = 100
|
||||||
|
class_property from = 1_000
|
||||||
|
class_property to = 50_000
|
||||||
|
class_property incr = 1_000
|
||||||
end
|
end
|
||||||
|
|
||||||
def report(storage, nb_run, name, &block)
|
def report(storage, name, &block)
|
||||||
durations = run_n_times nb_run, &block
|
durations = run_n_times Context.nb_run, &block
|
||||||
File.open("#{Context.report_dir}/#{name}", "w") do |file|
|
File.open("#{Context.report_dir}/#{name}.raw", "w") do |file|
|
||||||
durations.each do |d|
|
durations.each do |d|
|
||||||
file.puts d
|
file.puts d
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
avr = durations.reduce { |a, b| a + b } / nb_run
|
avr = durations.reduce { |a, b| a + b } / Context.nb_run
|
||||||
puts "#{name}: #{avr}"
|
puts "#{name}: #{avr}"
|
||||||
avr
|
avr
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_env(storage, db_size, name, s_index, s_partition, s_tags, &)
|
def long_operation(text)
|
||||||
STDOUT.write "add #{db_size} values to #{name}\r".to_slice
|
STDOUT.write "#{text}\r".to_slice
|
||||||
index_max_iterations = ENV["INDEXESMAXIT"].to_i rescue 5_000
|
yield
|
||||||
add_cars storage, db_size, max_it_tags: (db_size > index_max_iterations ? 0 : 5000)
|
|
||||||
STDOUT.write " \r".to_slice
|
STDOUT.write " \r".to_slice
|
||||||
|
|
||||||
yield storage, name, s_index, s_partition, s_tags
|
|
||||||
|
|
||||||
storage.rm_storage_dir
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def batch(db_size, nb_run)
|
def verbose_add_cars(storage, nbcars, name, max_indexes)
|
||||||
|
long_operation "add #{nbcars} values to #{name}" do
|
||||||
|
add_cars storage, nbcars, max_indexes: max_indexes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Add first entries, then loop: speed tests, add entries.
|
||||||
|
def prepare_env(storage, name, s_index, s_partition, s_tags, &)
|
||||||
|
verbose_add_cars storage, Context.from, name, max_indexes: Context.max_indexes
|
||||||
|
|
||||||
|
current = Context.from
|
||||||
|
to = Context.to
|
||||||
|
incr = Context.incr
|
||||||
|
|
||||||
|
while current < to
|
||||||
|
yield storage, current, name, s_index, s_partition, s_tags
|
||||||
|
|
||||||
|
break if current + incr >= to
|
||||||
|
|
||||||
|
verbose_add_cars storage, incr, name, max_indexes: Context.max_indexes
|
||||||
|
current += incr
|
||||||
|
end
|
||||||
|
|
||||||
|
long_operation "removing #{name} data" { storage.rm_storage_dir }
|
||||||
|
end
|
||||||
|
|
||||||
|
def batch()
|
||||||
cars_ram = DODB::RAMOnlySpecDataBase(Car).new
|
cars_ram = DODB::RAMOnlySpecDataBase(Car).new
|
||||||
cars_cached = DODB::CachedSpecDataBase(Car).new
|
cars_cached = DODB::CachedSpecDataBase(Car).new
|
||||||
cars_semi = DODB::SpecDataBase(Car).new "-semi"
|
cars_semi = DODB::SpecDataBase(Car).new "-semi"
|
||||||
|
@ -58,42 +84,38 @@ def batch(db_size, nb_run)
|
||||||
semi_Sby_name, semi_Sby_color, semi_Sby_keywords = cached_indexes cars_semi
|
semi_Sby_name, semi_Sby_color, semi_Sby_keywords = cached_indexes cars_semi
|
||||||
uncached_Sby_name, uncached_Sby_color, uncached_Sby_keywords = uncached_indexes cars_uncached
|
uncached_Sby_name, uncached_Sby_color, uncached_Sby_keywords = uncached_indexes cars_uncached
|
||||||
|
|
||||||
car_name_to_search = ENV["CARNAME"] rescue "Corvet-#{(db_size/2).to_i}"
|
|
||||||
car_color_to_search = ENV["CARCOLOR"] rescue "red"
|
|
||||||
car_keyword_to_search = ENV["CARKEYWORD"] rescue "spacious"
|
|
||||||
|
|
||||||
puts ""
|
|
||||||
puts "NEW BATCH: db-size #{db_size}"
|
|
||||||
puts ""
|
|
||||||
puts "search by index '#{car_name_to_search}', partition '#{car_color_to_search}', tag '#{car_keyword_to_search}'"
|
|
||||||
|
|
||||||
fn = ->(storage : DODB::Storage(Car),
|
fn = ->(storage : DODB::Storage(Car),
|
||||||
|
current_db_size : Int32,
|
||||||
name : String,
|
name : String,
|
||||||
search_name : DODB::Index(Car),
|
search_name : DODB::Index(Car),
|
||||||
search_color : DODB::Partition(Car),
|
search_color : DODB::Partition(Car),
|
||||||
search_keywords : DODB::Tags(Car)) {
|
search_keywords : DODB::Tags(Car)) {
|
||||||
report(storage, nb_run, "#{name}_#{db_size}_index") do
|
|
||||||
corvet = search_name.get car_name_to_search
|
name_to_search = ENV["CARNAME"] rescue "Corvet-#{(current_db_size/2).to_i}"
|
||||||
|
color_to_search = ENV["CARCOLOR"] rescue "red"
|
||||||
|
keyword_to_search = ENV["CARKEYWORD"] rescue "spacious"
|
||||||
|
puts "NEW BATCH: db-size #{current_db_size}, name: '#{name_to_search}', color: '#{color_to_search}', tag: '#{keyword_to_search}'"
|
||||||
|
report(storage, "#{name}_#{current_db_size}_index") do
|
||||||
|
corvet = search_name.get name_to_search
|
||||||
end
|
end
|
||||||
report(storage, nb_run, "#{name}_#{db_size}_partitions") do
|
report(storage, "#{name}_#{current_db_size}_partitions") do
|
||||||
corvet = search_color.get? car_color_to_search
|
corvet = search_color.get? color_to_search
|
||||||
end
|
end
|
||||||
report(storage, nb_run, "#{name}_#{db_size}_tags") do
|
report(storage, "#{name}_#{current_db_size}_tags") do
|
||||||
corvet = search_keywords.get? car_keyword_to_search
|
corvet = search_keywords.get? keyword_to_search
|
||||||
end
|
end
|
||||||
puts ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_env cars_ram, db_size, "ram", ram_Sby_name, ram_Sby_color, ram_Sby_keywords, &fn
|
prepare_env cars_cached, "cached", cached_Sby_name, cached_Sby_color, cached_Sby_keywords, &fn
|
||||||
prepare_env cars_cached, db_size, "cached", cached_Sby_name, cached_Sby_color, cached_Sby_keywords, &fn
|
prepare_env cars_ram, "ram", ram_Sby_name, ram_Sby_color, ram_Sby_keywords, &fn
|
||||||
prepare_env cars_semi, db_size, "semi", semi_Sby_name, semi_Sby_color, semi_Sby_keywords, &fn
|
prepare_env cars_semi, "semi", semi_Sby_name, semi_Sby_color, semi_Sby_keywords, &fn
|
||||||
prepare_env cars_uncached, db_size, "uncached", uncached_Sby_name, uncached_Sby_color, uncached_Sby_keywords, &fn
|
prepare_env cars_uncached, "uncached", uncached_Sby_name, uncached_Sby_color, uncached_Sby_keywords, &fn
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_add(storage : DODB::Storage(Car), nb_run)
|
def perform_add(storage : DODB::Storage(Car))
|
||||||
corvet0 = Car.new "Corvet", "red", [ "shiny", "impressive", "fast", "elegant" ]
|
corvet0 = Car.new "Corvet", "red", [ "shiny", "impressive", "fast", "elegant" ]
|
||||||
i = 0
|
i = 0
|
||||||
perform_benchmark_average nb_run, do
|
perform_benchmark_average Context.nb_run, do
|
||||||
corvet = corvet0.clone
|
corvet = corvet0.clone
|
||||||
corvet.name = "Corvet-#{i}"
|
corvet.name = "Corvet-#{i}"
|
||||||
storage << corvet
|
storage << corvet
|
||||||
|
@ -101,7 +123,7 @@ def perform_add(storage : DODB::Storage(Car), nb_run)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def batch_add(nb_run)
|
def batch_add()
|
||||||
cars_ram = DODB::RAMOnlySpecDataBase(Car).new
|
cars_ram = DODB::RAMOnlySpecDataBase(Car).new
|
||||||
cars_cached = DODB::CachedSpecDataBase(Car).new
|
cars_cached = DODB::CachedSpecDataBase(Car).new
|
||||||
cars_semi = DODB::SpecDataBase(Car).new "-semi"
|
cars_semi = DODB::SpecDataBase(Car).new "-semi"
|
||||||
|
@ -112,17 +134,17 @@ def batch_add(nb_run)
|
||||||
cached_indexes cars_semi
|
cached_indexes cars_semi
|
||||||
uncached_indexes cars_uncached
|
uncached_indexes cars_uncached
|
||||||
|
|
||||||
avr = perform_add(cars_ram, nb_run)
|
avr = perform_add(cars_ram)
|
||||||
puts "(ram db and indexes) add a value (average on #{nb_run} tries): #{avr}"
|
puts "(ram db and indexes) add a value (average on #{Context.nb_run} tries): #{avr}"
|
||||||
|
|
||||||
avr = perform_add(cars_cached, nb_run)
|
avr = perform_add(cars_cached)
|
||||||
puts "(cached db and indexes) add a value (average on #{nb_run} tries): #{avr}"
|
puts "(cached db and indexes) add a value (average on #{Context.nb_run} tries): #{avr}"
|
||||||
|
|
||||||
avr = perform_add(cars_semi, nb_run)
|
avr = perform_add(cars_semi)
|
||||||
puts "(uncached db but cached indexes) add a value (average on #{nb_run} tries): #{avr}"
|
puts "(uncached db but cached indexes) add a value (average on #{Context.nb_run} tries): #{avr}"
|
||||||
|
|
||||||
avr = perform_add(cars_uncached, nb_run)
|
avr = perform_add(cars_uncached)
|
||||||
puts "(uncached db and indexes) add a value (average on #{nb_run} tries): #{avr}"
|
puts "(uncached db and indexes) add a value (average on #{Context.nb_run} tries): #{avr}"
|
||||||
|
|
||||||
cars_ram.rm_storage_dir
|
cars_ram.rm_storage_dir
|
||||||
cars_cached.rm_storage_dir
|
cars_cached.rm_storage_dir
|
||||||
|
@ -130,32 +152,20 @@ def batch_add(nb_run)
|
||||||
cars_uncached.rm_storage_dir
|
cars_uncached.rm_storage_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
ENV["REPORT_DIR"]?.try do |report_dir|
|
ENV["REPORT_DIR"]?.try { |report_dir| Context.report_dir = report_dir }
|
||||||
Context.report_dir = report_dir
|
|
||||||
end
|
|
||||||
Dir.mkdir_p Context.report_dir
|
Dir.mkdir_p Context.report_dir
|
||||||
|
|
||||||
nb_run = ENV["NBRUN"].to_i rescue 100
|
ENV["MAXINDEXES"]?.try { |it| Context.max_indexes = it.to_i }
|
||||||
db_size_max = ENV["DBSIZE"].to_i rescue 40_000
|
ENV["NBRUN"]?.try { |it| Context.nb_run = it.to_i }
|
||||||
current_size = ENV["DBSIZE_START"].to_i rescue 5_000
|
ENV["DBSIZE"]?.try { |it| Context.to = it.to_i }
|
||||||
size_increment = ENV["DBSIZE_INCREMENT"].to_i rescue 1_000
|
ENV["DBSIZE_START"]?.try { |it| Context.from = it.to_i }
|
||||||
index_max_iterations = ENV["INDEXESMAXIT"].to_i rescue 5_000
|
ENV["DBSIZE_INCREMENT"]?.try { |it| Context.incr = it.to_i }
|
||||||
|
|
||||||
# ENV["DBSIZE"] rescue 40_000
|
pp! Context.nb_run
|
||||||
# ENV["DBSIZE_START"] rescue 5_000
|
pp! Context.from
|
||||||
# ENV["DBSIZE_INCREMENT"] rescue 1_000
|
pp! Context.to
|
||||||
# ENV["REPORT_DIR"] rescue "results"
|
pp! Context.incr
|
||||||
# ENV["NBRUN"] rescue 100
|
pp! Context.max_indexes
|
||||||
# ENV["INDEXESMAXIT"] rescue 5000
|
|
||||||
|
|
||||||
pp! nb_run
|
batch
|
||||||
pp! db_size_max
|
batch_add
|
||||||
pp! current_size
|
|
||||||
pp! size_increment
|
|
||||||
pp! index_max_iterations
|
|
||||||
|
|
||||||
while current_size <= db_size_max
|
|
||||||
batch current_size, nb_run
|
|
||||||
current_size += size_increment
|
|
||||||
end
|
|
||||||
batch_add nb_run
|
|
||||||
|
|
|
@ -51,8 +51,12 @@ def uncached_indexes(storage : DODB::Storage)
|
||||||
return n, c, k
|
return n, c, k
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_cars(storage : DODB::Storage, nb_iterations : Int32, from = 0, max_it_tags = 5000)
|
# `max_indexes` limits the number of indexes (partitions and tags).
|
||||||
i = from
|
# Once the last index (db last_index/5) is above this value, the following
|
||||||
|
# cars won't be tagged nor partitionned.
|
||||||
|
def add_cars(storage : DODB::Storage, nb_iterations : Int32, max_indexes = 5000)
|
||||||
|
last_index = ((storage.last_index + 1) / 5).to_i
|
||||||
|
i = 0
|
||||||
car1 = Car.new "Corvet", "red", [ "shiny", "impressive", "fast", "elegant" ]
|
car1 = Car.new "Corvet", "red", [ "shiny", "impressive", "fast", "elegant" ]
|
||||||
car2 = Car.new "Bullet-GT", "blue", [ "shiny", "fast", "expensive" ]
|
car2 = Car.new "Bullet-GT", "blue", [ "shiny", "fast", "expensive" ]
|
||||||
car3 = Car.new "Deudeuche", "beige", [ "curvy", "sublime" ]
|
car3 = Car.new "Deudeuche", "beige", [ "curvy", "sublime" ]
|
||||||
|
@ -60,13 +64,15 @@ def add_cars(storage : DODB::Storage, nb_iterations : Int32, from = 0, max_it_ta
|
||||||
car5 = Car.new "C-MAX", "gray", [ "spacious", "affordable" ]
|
car5 = Car.new "C-MAX", "gray", [ "spacious", "affordable" ]
|
||||||
|
|
||||||
while i < nb_iterations
|
while i < nb_iterations
|
||||||
car1.name = "Corvet-#{i}"
|
car1.name = "Corvet-#{last_index}"
|
||||||
car2.name = "Bullet-GT-#{i}"
|
car2.name = "Bullet-GT-#{last_index}"
|
||||||
car3.name = "Deudeuche-#{i}"
|
car3.name = "Deudeuche-#{last_index}"
|
||||||
car4.name = "Ford-5-#{i}"
|
car4.name = "Ford-5-#{last_index}"
|
||||||
car5.name = "C-MAX-#{i}"
|
car5.name = "C-MAX-#{last_index}"
|
||||||
|
|
||||||
if i >= max_it_tags
|
last_index += 1
|
||||||
|
|
||||||
|
if last_index > max_indexes
|
||||||
car1.color = DODB.no_index
|
car1.color = DODB.no_index
|
||||||
car2.color = DODB.no_index
|
car2.color = DODB.no_index
|
||||||
car3.color = DODB.no_index
|
car3.color = DODB.no_index
|
||||||
|
|
Loading…
Reference in New Issue