Finally a concise way to perform tests on different databases.
parent
53c69d0c5d
commit
8161ea3f82
|
@ -6,10 +6,11 @@ require "./db-cars.cr"
|
|||
# ENV["CARNAME"] rescue "Corvet-#{(db_size/2).to_i}"
|
||||
# ENV["CARCOLOR"] rescue "red"
|
||||
# ENV["CARKEYWORD"] rescue "spacious"
|
||||
# ENV["DBSIZE"] rescue 1_000
|
||||
# ENV["DBSIZE"] rescue 40_000
|
||||
# ENV["DBSIZE_START"] rescue 5_000
|
||||
# ENV["DBSIZE_INCREMENT"] rescue 5_000
|
||||
# ENV["DBSIZE_INCREMENT"] rescue 1_000
|
||||
# ENV["REPORT_DIR"] rescue "results"
|
||||
# ENV["NBRUN"] rescue 100
|
||||
|
||||
class DODB::Storage(V)
|
||||
def empty_db
|
||||
|
@ -22,9 +23,7 @@ class Context
|
|||
class_property report_dir = "results"
|
||||
end
|
||||
|
||||
def report(storage, db_size, nb_run, name, title, &block)
|
||||
#add_cars storage, db_size
|
||||
|
||||
def report(storage, nb_run, name, &block)
|
||||
durations = run_n_times nb_run, &block
|
||||
File.open("#{Context.report_dir}/#{name}", "w") do |file|
|
||||
durations.each do |d|
|
||||
|
@ -32,12 +31,20 @@ def report(storage, db_size, nb_run, name, title, &block)
|
|||
end
|
||||
end
|
||||
avr = durations.reduce { |a, b| a + b } / nb_run
|
||||
puts "#{title}: #{avr}"
|
||||
#storage.empty_db
|
||||
|
||||
puts "#{name}: #{avr}"
|
||||
avr
|
||||
end
|
||||
|
||||
def prepare_env(storage, db_size, name, s_index, s_partition, s_tags, &)
|
||||
STDOUT.write "add #{db_size} values to #{name}\r".to_slice
|
||||
add_cars storage, db_size
|
||||
STDOUT.write " \r".to_slice
|
||||
|
||||
yield storage, name, s_index, s_partition, s_tags
|
||||
|
||||
storage.rm_storage_dir
|
||||
end
|
||||
|
||||
def batch(db_size, nb_run)
|
||||
cars_ram = DODB::RAMOnlySpecDataBase(Car).new
|
||||
cars_cached = DODB::CachedSpecDataBase(Car).new
|
||||
|
@ -49,96 +56,46 @@ def batch(db_size, nb_run)
|
|||
semi_searchby_name, semi_searchby_color, semi_searchby_keywords = cached_indexes cars_semi
|
||||
uncached_searchby_name, uncached_searchby_color, uncached_searchby_keywords = uncached_indexes cars_uncached
|
||||
|
||||
puts "add some values"
|
||||
add_cars cars_ram, db_size
|
||||
add_cars cars_cached, db_size
|
||||
add_cars cars_semi, db_size
|
||||
add_cars cars_uncached, db_size
|
||||
#puts "add some values"
|
||||
#add_cars cars_ram, db_size
|
||||
#add_cars cars_cached, db_size
|
||||
#add_cars cars_semi, db_size
|
||||
#add_cars cars_uncached, db_size
|
||||
|
||||
# Searching for data with an index.
|
||||
car_name_to_search = ENV["CARNAME"] rescue "Corvet-#{(db_size/2).to_i}"
|
||||
puts "search by index '#{car_name_to_search}': get a single value"
|
||||
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"
|
||||
|
||||
report(cars_ram, db_size, nb_run, "ram_#{db_size}_index", "(ram db and index) searching with an index") do
|
||||
corvet = ram_searchby_name.get car_name_to_search
|
||||
end
|
||||
puts ""
|
||||
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}'"
|
||||
|
||||
report(cars_cached, db_size, nb_run, "cached_#{db_size}_index", "(cached db and index) searching with an index") do
|
||||
corvet = cached_searchby_name.get car_name_to_search
|
||||
end
|
||||
fn = ->(storage : DODB::Storage(Car),
|
||||
name : String,
|
||||
search_name : DODB::Index(Car),
|
||||
search_color : DODB::Partition(Car),
|
||||
search_keywords : DODB::Tags(Car)) {
|
||||
report(storage, nb_run, "#{name}_#{db_size}_index") do
|
||||
corvet = search_name.get car_name_to_search
|
||||
end
|
||||
report(storage, nb_run, "#{name}_#{db_size}_partitions") do
|
||||
corvet = search_color.get car_color_to_search
|
||||
end
|
||||
report(storage, nb_run, "#{name}_#{db_size}_tags") do
|
||||
corvet = search_keywords.get car_keyword_to_search
|
||||
end
|
||||
}
|
||||
|
||||
report(cars_semi, db_size, nb_run, "semi_#{db_size}_index", "(semi: uncached db but cached index) searching with an index") do
|
||||
corvet = semi_searchby_name.get car_name_to_search
|
||||
end
|
||||
|
||||
report(cars_uncached, db_size, nb_run, "uncached_#{db_size}_index", "(uncached db and index) searching with an index") do
|
||||
corvet = uncached_searchby_name.get car_name_to_search
|
||||
end
|
||||
|
||||
# # Searching for data with a partition.
|
||||
# car_color_to_search = ENV["CARCOLOR"] rescue "red"
|
||||
# puts ""
|
||||
# puts "search by partition #{car_color_to_search}: get #{ram_searchby_color.get(car_color_to_search).size} values"
|
||||
# Benchmark.ips do |x|
|
||||
# add_cars cars_ram, db_size
|
||||
# x.report("(ram db and partition) searching with a partition") do
|
||||
# corvet = ram_searchby_color.get car_color_to_search
|
||||
# end
|
||||
# cars_ram.empty_db
|
||||
#
|
||||
# add_cars cars_cached, db_size
|
||||
# x.report("(cached db and partition) searching with a partition") do
|
||||
# corvet = cached_searchby_color.get car_color_to_search
|
||||
# end
|
||||
# cars_cached.empty_db
|
||||
#
|
||||
# add_cars cars_semi, db_size
|
||||
# x.report("(semi: uncached db but cached partition) searching with a partition") do
|
||||
# corvet = semi_searchby_color.get car_color_to_search
|
||||
# end
|
||||
# cars_semi.empty_db
|
||||
#
|
||||
# add_cars cars_uncached, db_size
|
||||
# x.report("(uncached db and partition) searching with a partition") do
|
||||
# corvet = uncached_searchby_color.get car_color_to_search
|
||||
# end
|
||||
# cars_uncached.empty_db
|
||||
# end
|
||||
#
|
||||
# # Searching for data with a tag.
|
||||
# car_keyword_to_search = ENV["CARKEYWORD"] rescue "spacious"
|
||||
# puts ""
|
||||
# puts "search by tag #{car_keyword_to_search}: get #{ram_searchby_keywords.get(car_keyword_to_search).size} values"
|
||||
# Benchmark.ips do |x|
|
||||
# add_cars cars_ram, db_size
|
||||
# x.report("(ram db and tag) searching with a tag") do
|
||||
# corvet = ram_searchby_keywords.get car_keyword_to_search
|
||||
# end
|
||||
# cars_ram.empty_db
|
||||
#
|
||||
# add_cars cars_cached, db_size
|
||||
# x.report("(cached db and tag) searching with a tag") do
|
||||
# corvet = cached_searchby_keywords.get car_keyword_to_search
|
||||
# end
|
||||
# cars_cached.empty_db
|
||||
#
|
||||
# add_cars cars_semi, db_size
|
||||
# x.report("(semi: uncached db but cached tag) searching with a tag") do
|
||||
# corvet = semi_searchby_keywords.get car_keyword_to_search
|
||||
# end
|
||||
# cars_semi.empty_db
|
||||
#
|
||||
# add_cars cars_uncached, db_size
|
||||
# x.report("(uncached db and tag) searching with a tag") do
|
||||
# corvet = uncached_searchby_keywords.get car_keyword_to_search
|
||||
# end
|
||||
# cars_uncached.empty_db
|
||||
# end
|
||||
|
||||
cars_ram.rm_storage_dir
|
||||
cars_cached.rm_storage_dir
|
||||
cars_semi.rm_storage_dir
|
||||
cars_uncached.rm_storage_dir
|
||||
prepare_env cars_ram, db_size, "ram_db_and_indexes",
|
||||
ram_searchby_name, ram_searchby_color, ram_searchby_keywords, &fn
|
||||
prepare_env cars_cached, db_size, "cached_db_and_indexes",
|
||||
cached_searchby_name, cached_searchby_color, cached_searchby_keywords, &fn
|
||||
prepare_env cars_semi, db_size, "semi_uncached_db_and_cached_indexes",
|
||||
semi_searchby_name, semi_searchby_color, semi_searchby_keywords, &fn
|
||||
prepare_env cars_uncached, db_size, "uncached_db_and_indexes",
|
||||
uncached_searchby_name, uncached_searchby_color, uncached_searchby_keywords, &fn
|
||||
end
|
||||
|
||||
def perform_add(storage : DODB::Storage(Car), nb_run)
|
||||
|
@ -186,10 +143,22 @@ ENV["REPORT_DIR"]?.try do |report_dir|
|
|||
end
|
||||
Dir.mkdir_p Context.report_dir
|
||||
|
||||
nb_run = 1000
|
||||
db_size_max = ENV["DBSIZE"].to_i rescue 1_000
|
||||
nb_run = ENV["NBRUN"].to_i rescue 100
|
||||
db_size_max = ENV["DBSIZE"].to_i rescue 40_000
|
||||
current_size = ENV["DBSIZE_START"].to_i rescue 5_000
|
||||
size_increment = ENV["DBSIZE_INCREMENT"].to_i rescue 5_000
|
||||
size_increment = ENV["DBSIZE_INCREMENT"].to_i rescue 1_000
|
||||
|
||||
# ENV["DBSIZE"] rescue 40_000
|
||||
# ENV["DBSIZE_START"] rescue 5_000
|
||||
# ENV["DBSIZE_INCREMENT"] rescue 1_000
|
||||
# ENV["REPORT_DIR"] rescue "results"
|
||||
# ENV["NBRUN"] rescue 100
|
||||
|
||||
pp! nb_run
|
||||
pp! db_size_max
|
||||
pp! current_size
|
||||
pp! size_increment
|
||||
|
||||
while current_size <= db_size_max
|
||||
batch current_size, nb_run
|
||||
current_size += size_increment
|
||||
|
|
Loading…
Reference in New Issue