minor: benchmark fix

This commit is contained in:
Kyle Banker 2009-11-17 17:47:49 -05:00
parent e1e6d4339a
commit a4aff9bc26

View File

@ -64,13 +64,11 @@ def benchmark(str, n, coll_name, data, create_index=false)
coll.create_index('x') if create_index coll.create_index('x') if create_index
profile(str) do profile(str) do
times = [] times = []
TRIALS.times do
GC.start GC.start
t1 = Time.now t1 = Time.now
n.times { |i| yield(coll, i) } n.times { |i| yield(coll, i) }
t2 = Time.now t2 = Time.now
times << t2 - t1 times << t2 - t1
end
report(str, times.min) report(str, times.min)
end end
end end
@ -86,6 +84,7 @@ def benchmark_insert(desc, coll_name, data)
benchmark(desc, PER_TRIAL, coll_name, data) do |coll, i| benchmark(desc, PER_TRIAL, coll_name, data) do |coll, i|
data['x'] = i data['x'] = i
coll.insert(data) coll.insert(data)
data.delete(:_id)
end end
end end
@ -93,6 +92,7 @@ def benchmark_insert_index(desc, coll_name, data)
benchmark(desc, PER_TRIAL, coll_name, data, true) do |coll, i| benchmark(desc, PER_TRIAL, coll_name, data, true) do |coll, i|
data['x'] = i data['x'] = i
coll.insert(data) coll.insert(data)
data.delete(:_id)
end end
end end
@ -108,6 +108,7 @@ def benchmark_insert_batch(desc, coll_name, data)
benchmark(desc, PER_TRIAL / BATCH_SIZE, coll_name, data) do |coll, i| benchmark(desc, PER_TRIAL / BATCH_SIZE, coll_name, data) do |coll, i|
data['x'] = i data['x'] = i
coll.insert([data] * BATCH_SIZE) coll.insert([data] * BATCH_SIZE)
data.delete(:_id)
end end
end end