dodb.cr/spec/benchmark-cars.cr

110 lines
3.6 KiB
Crystal
Raw Normal View History

require "benchmark"
require "./benchmark-utilities.cr"
require "./cars.cr"
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
2024-05-06 18:31:52 +02:00
add_cars cars_semi, 1_000
add_cars cars_uncached, 1_000
# Searching for data with an index.
puts "search by index 'Corvet-500': get a single value"
Benchmark.ips do |x|
x.report("(ram db and index) searching a data with an index") do
corvet = ram_searchby_name.get "Corvet-500"
end
x.report("(cached db and index) searching a data with an index") do
corvet = cached_searchby_name.get "Corvet-500"
end
x.report("(semi: uncached db but cached index) searching a data with an index") do
2024-05-06 18:31:52 +02:00
corvet = semi_searchby_name.get "Corvet-500"
end
x.report("(uncached db and index) searching a data with an index") do
corvet = uncached_searchby_name.get "Corvet-500"
end
end
# Searching for data with a partition.
puts ""
puts "search by partition 'red': get #{ram_searchby_color.get("red").size} values"
Benchmark.ips do |x|
x.report("(ram db and partition) searching a data with a partition") do
corvet = ram_searchby_color.get "red"
end
x.report("(cached db and partition) searching a data with a partition") do
corvet = cached_searchby_color.get "red"
end
x.report("(semi: uncached db but cached partition) searching a data with a partition") do
corvet = semi_searchby_color.get "red"
2024-05-06 18:31:52 +02:00
end
x.report("(uncached db and partition) searching a data with a partition") do
corvet = uncached_searchby_color.get "red"
end
end
# Searching for data with a tag.
puts ""
puts "search by tag 'spacious': get #{ram_searchby_keywords.get("spacious").size} values"
Benchmark.ips do |x|
x.report("(ram db and tag) searching a data with a tag") do
corvet = ram_searchby_keywords.get "spacious"
end
x.report("(cached db and tag) searching a data with a tag") do
corvet = cached_searchby_keywords.get "spacious"
2024-05-06 18:31:52 +02:00
end
x.report("(semi: uncached db but cached tag) searching a data with a tag") do
corvet = semi_searchby_keywords.get "spacious"
end
x.report("(uncached db and tag) searching a data with a tag") do
corvet = uncached_searchby_keywords.get "spacious"
end
end
#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