130 lines
4.4 KiB
Crystal
130 lines
4.4 KiB
Crystal
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
|
|
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
|
|
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"
|
|
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"
|
|
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_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
|