require "./db-cars.cr" require "./utilities.cr" class Context class_property dbsize = 1_000_000 class_property nb_run = 100 end ENV["DBSIZE"]?.try { |it| Context.dbsize = it.to_i } ENV["NBRUN"]?.try { |it| Context.nb_run = it.to_i } if ARGV.size == 0 puts "Usage: high-volume-db (add|get)" exit 0 end db = DODB::Storage::Common(Car).new "TESTDB", 5000 by_name = db.new_index "name", &.name something = Hash(String,Bool).new case ARGV[0] when /get/ counter = 0 car_number_to_get = (Context.dbsize/2).to_i puts "let's get the car #{car_number_to_get}" avr = perform_benchmark_average Context.nb_run, do car = by_name.get "somecar-#{car_number_to_get}" something[car.name] = true #STDOUT.write "\rgot the car #{car.name}: #{counter}/#{Context.nb_run}".to_slice counter += 1 end puts puts "average time was: #{avr}" puts "done!" when /add/ counter = db.last_key while counter < Context.dbsize STDOUT.write "\radding car #{counter}/#{Context.dbsize}".to_slice db << Car.new "somecar-#{counter}", "red", [] of String counter += 1 end puts puts "done!" end