2024-05-04 23:12:32 +02:00
|
|
|
require "benchmark"
|
2024-05-10 15:23:28 +02:00
|
|
|
require "./utilities.cr"
|
|
|
|
require "./db-cars.cr"
|
2024-05-04 23:12:32 +02:00
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
# List of environment variables and default values:
|
|
|
|
# ENV["CARNAME"] rescue "Corvet-#{(db_size/2).to_i}"
|
|
|
|
# ENV["CARCOLOR"] rescue "red"
|
|
|
|
# ENV["CARKEYWORD"] rescue "spacious"
|
2024-05-11 01:48:27 +02:00
|
|
|
# ENV["DBSIZE"] rescue 40_000
|
2024-05-10 17:57:07 +02:00
|
|
|
# ENV["DBSIZE_START"] rescue 5_000
|
2024-05-11 01:48:27 +02:00
|
|
|
# ENV["DBSIZE_INCREMENT"] rescue 1_000
|
2024-05-10 17:57:07 +02:00
|
|
|
# ENV["REPORT_DIR"] rescue "results"
|
2024-05-11 01:48:27 +02:00
|
|
|
# ENV["NBRUN"] rescue 100
|
2024-05-12 03:11:53 +02:00
|
|
|
# ENV["INDEXESMAXIT"] rescue 5000
|
2024-05-10 17:57:07 +02:00
|
|
|
|
|
|
|
class DODB::Storage(V)
|
|
|
|
def empty_db
|
|
|
|
while pop
|
|
|
|
end
|
2024-05-09 18:41:20 +02:00
|
|
|
end
|
2024-05-10 17:57:07 +02:00
|
|
|
end
|
2024-05-09 18:41:20 +02:00
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
class Context
|
|
|
|
class_property report_dir = "results"
|
|
|
|
end
|
2024-05-04 23:12:32 +02:00
|
|
|
|
2024-05-11 01:48:27 +02:00
|
|
|
def report(storage, nb_run, name, &block)
|
2024-05-10 17:57:07 +02:00
|
|
|
durations = run_n_times nb_run, &block
|
|
|
|
File.open("#{Context.report_dir}/#{name}", "w") do |file|
|
|
|
|
durations.each do |d|
|
|
|
|
file.puts d
|
|
|
|
end
|
2024-05-04 23:12:32 +02:00
|
|
|
end
|
2024-05-10 17:57:07 +02:00
|
|
|
avr = durations.reduce { |a, b| a + b } / nb_run
|
2024-05-11 01:48:27 +02:00
|
|
|
puts "#{name}: #{avr}"
|
2024-05-10 17:57:07 +02:00
|
|
|
avr
|
2024-05-04 23:12:32 +02:00
|
|
|
end
|
|
|
|
|
2024-05-11 01:48:27 +02:00
|
|
|
def prepare_env(storage, db_size, name, s_index, s_partition, s_tags, &)
|
|
|
|
STDOUT.write "add #{db_size} values to #{name}\r".to_slice
|
2024-05-12 03:11:53 +02:00
|
|
|
index_max_iterations = ENV["INDEXESMAXIT"].to_i rescue 5_000
|
|
|
|
add_cars storage, db_size, max_it_tags: (db_size > index_max_iterations ? 0 : 5000)
|
2024-05-11 01:48:27 +02:00
|
|
|
STDOUT.write " \r".to_slice
|
|
|
|
|
|
|
|
yield storage, name, s_index, s_partition, s_tags
|
|
|
|
|
|
|
|
storage.rm_storage_dir
|
|
|
|
end
|
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
def batch(db_size, nb_run)
|
|
|
|
cars_ram = DODB::RAMOnlySpecDataBase(Car).new
|
|
|
|
cars_cached = DODB::CachedSpecDataBase(Car).new
|
|
|
|
cars_semi = DODB::SpecDataBase(Car).new "-semi"
|
|
|
|
cars_uncached = DODB::SpecDataBase(Car).new
|
2024-05-09 18:41:20 +02:00
|
|
|
|
2024-05-11 02:19:03 +02:00
|
|
|
ram_Sby_name, ram_Sby_color, ram_Sby_keywords = ram_indexes cars_ram
|
|
|
|
cached_Sby_name, cached_Sby_color, cached_Sby_keywords = cached_indexes cars_cached
|
|
|
|
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
|
2024-05-11 01:48:27 +02:00
|
|
|
|
|
|
|
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),
|
|
|
|
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
|
2024-05-12 03:11:53 +02:00
|
|
|
corvet = search_color.get? car_color_to_search
|
2024-05-11 01:48:27 +02:00
|
|
|
end
|
|
|
|
report(storage, nb_run, "#{name}_#{db_size}_tags") do
|
2024-05-12 03:11:53 +02:00
|
|
|
corvet = search_keywords.get? car_keyword_to_search
|
2024-05-11 01:48:27 +02:00
|
|
|
end
|
2024-05-11 02:19:03 +02:00
|
|
|
puts ""
|
2024-05-11 01:48:27 +02:00
|
|
|
}
|
|
|
|
|
2024-05-11 02:19:03 +02:00
|
|
|
prepare_env cars_ram, db_size, "ram", ram_Sby_name, ram_Sby_color, ram_Sby_keywords, &fn
|
|
|
|
prepare_env cars_cached, db_size, "cached", cached_Sby_name, cached_Sby_color, cached_Sby_keywords, &fn
|
|
|
|
prepare_env cars_semi, db_size, "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
|
2024-05-10 17:57:07 +02:00
|
|
|
end
|
2024-05-10 02:57:55 +02:00
|
|
|
|
|
|
|
def perform_add(storage : DODB::Storage(Car), nb_run)
|
|
|
|
corvet0 = Car.new "Corvet", "red", [ "shiny", "impressive", "fast", "elegant" ]
|
|
|
|
i = 0
|
|
|
|
perform_benchmark_average nb_run, do
|
|
|
|
corvet = corvet0.clone
|
2024-05-10 15:23:28 +02:00
|
|
|
corvet.name = "Corvet-#{i}"
|
2024-05-10 02:57:55 +02:00
|
|
|
storage << corvet
|
|
|
|
i += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
def batch_add(nb_run)
|
|
|
|
cars_ram = DODB::RAMOnlySpecDataBase(Car).new
|
|
|
|
cars_cached = DODB::CachedSpecDataBase(Car).new
|
|
|
|
cars_semi = DODB::SpecDataBase(Car).new "-semi"
|
|
|
|
cars_uncached = DODB::SpecDataBase(Car).new
|
|
|
|
|
2024-05-11 02:19:03 +02:00
|
|
|
ram_indexes cars_ram
|
|
|
|
cached_indexes cars_cached
|
|
|
|
cached_indexes cars_semi
|
|
|
|
uncached_indexes cars_uncached
|
2024-05-10 02:57:55 +02:00
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
avr = perform_add(cars_ram, nb_run)
|
|
|
|
puts "(ram db and indexes) add a value (average on #{nb_run} tries): #{avr}"
|
2024-05-10 02:57:55 +02:00
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
avr = perform_add(cars_cached, nb_run)
|
|
|
|
puts "(cached db and indexes) add a value (average on #{nb_run} tries): #{avr}"
|
2024-05-10 02:57:55 +02:00
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
avr = perform_add(cars_semi, nb_run)
|
|
|
|
puts "(uncached db but cached indexes) add a value (average on #{nb_run} tries): #{avr}"
|
2024-05-10 02:57:55 +02:00
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
avr = perform_add(cars_uncached, nb_run)
|
|
|
|
puts "(uncached db and indexes) add a value (average on #{nb_run} tries): #{avr}"
|
|
|
|
|
|
|
|
cars_ram.rm_storage_dir
|
|
|
|
cars_cached.rm_storage_dir
|
|
|
|
cars_semi.rm_storage_dir
|
|
|
|
cars_uncached.rm_storage_dir
|
|
|
|
end
|
|
|
|
|
|
|
|
ENV["REPORT_DIR"]?.try do |report_dir|
|
|
|
|
Context.report_dir = report_dir
|
|
|
|
end
|
|
|
|
Dir.mkdir_p Context.report_dir
|
|
|
|
|
2024-05-11 01:48:27 +02:00
|
|
|
nb_run = ENV["NBRUN"].to_i rescue 100
|
|
|
|
db_size_max = ENV["DBSIZE"].to_i rescue 40_000
|
2024-05-10 17:57:07 +02:00
|
|
|
current_size = ENV["DBSIZE_START"].to_i rescue 5_000
|
2024-05-11 01:48:27 +02:00
|
|
|
size_increment = ENV["DBSIZE_INCREMENT"].to_i rescue 1_000
|
2024-05-12 03:11:53 +02:00
|
|
|
index_max_iterations = ENV["INDEXESMAXIT"].to_i rescue 5_000
|
2024-05-11 01:48:27 +02:00
|
|
|
|
|
|
|
# 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
|
2024-05-12 03:11:53 +02:00
|
|
|
# ENV["INDEXESMAXIT"] rescue 5000
|
2024-05-11 01:48:27 +02:00
|
|
|
|
|
|
|
pp! nb_run
|
|
|
|
pp! db_size_max
|
|
|
|
pp! current_size
|
|
|
|
pp! size_increment
|
2024-05-12 03:11:53 +02:00
|
|
|
pp! index_max_iterations
|
2024-05-11 01:48:27 +02:00
|
|
|
|
2024-05-10 17:57:07 +02:00
|
|
|
while current_size <= db_size_max
|
|
|
|
batch current_size, nb_run
|
|
|
|
current_size += size_increment
|
|
|
|
end
|
|
|
|
batch_add nb_run
|