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