Add some basic benchmark for adding values in different database types.

toying-with-ramdb
Philippe PITTOLI 2024-05-10 02:57:55 +02:00
parent 5ce24184be
commit 0389ed85ed
1 changed files with 47 additions and 27 deletions

View File

@ -79,31 +79,51 @@ Benchmark.ips do |x|
end
end
#cars_ram.rm_storage_dir
#cars_cached.rm_storage_dir
#cars_semi.rm_storage_dir
#cars_uncached.rm_storage_dir
cars_ram.rm_storage_dir
cars_cached.rm_storage_dir
cars_semi.rm_storage_dir
cars_uncached.rm_storage_dir
#cars_cached = DODB::CachedSpecDataBase(Car).new
#cars_uncached = DODB::SpecDataBase(Car).new
#
##init_indexes cars_cached
##init_indexes cars_uncached
#cached_searchby_name, cached_searchby_color, cached_searchby_keywords = cached_indexes cars_cached
#uncached_searchby_name, uncached_searchby_color, uncached_searchby_keywords = uncached_indexes cars_uncached
#
#add_cars cars_cached, 1_000
#add_cars cars_uncached, 1_000
#
#nb_run = 1000
#
#perform_benchmark_average_verbose "(cached) search db with an index", nb_run, do
# cached_searchby_name.get "Corvet-500"
#end
#
#perform_benchmark_average_verbose "(uncached) search db with an index", nb_run, do
# uncached_searchby_name.get "Corvet-500"
#end
#
#cars_cached.rm_storage_dir
#cars_uncached.rm_storage_dir
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
ram_searchby_name, ram_searchby_color, ram_searchby_keywords = ram_indexes cars_ram
cached_searchby_name, cached_searchby_color, cached_searchby_keywords = cached_indexes cars_cached
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
add_cars cars_ram, 1_000
add_cars cars_cached, 1_000
add_cars cars_semi, 1_000
add_cars cars_uncached, 1_000
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
corvet.name = "Corvet-add-#{i}"
storage << corvet
i += 1
end
end
nb_run = 1000
avr = perform_add(cars_ram, nb_run)
puts "(ram db and indexes) add a value (average on #{nb_run} tries): #{avr}"
avr = perform_add(cars_cached, nb_run)
puts "(cached db and indexes) add a value (average on #{nb_run} tries): #{avr}"
avr = perform_add(cars_semi, nb_run)
puts "(uncached db but cached indexes) add a value (average on #{nb_run} tries): #{avr}"
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