minor: benchmark updates
This commit is contained in:
parent
b82e29f313
commit
9fd352ec87
@ -6,6 +6,7 @@
|
||||
# The c-extension, mongo_ext, will be used if installed.
|
||||
|
||||
require 'rubygems'
|
||||
require 'benchmark'
|
||||
require 'mongo'
|
||||
|
||||
include Mongo
|
||||
@ -40,8 +41,13 @@ LARGE = {
|
||||
'developers','focus','building','mongodb','mongo'] * 20
|
||||
}
|
||||
|
||||
def report(str, t)
|
||||
printf("%s%d\n", str.ljust(60, '.'), PER_TRIAL / t)
|
||||
def print_headings
|
||||
puts "\n#{PER_TRIAL} documents or queries per trial. Batches of #{BATCH_SIZE} on batch inserts."
|
||||
printf("\n%s%-10s %-15s %-10s %-15s\n\n", "Test".ljust(40, ' '), "(real)", "(real ops/s)", "(user)", "(user ops/s)")
|
||||
end
|
||||
|
||||
def report(str, t, u=nil)
|
||||
printf("%s %-10.2f %-15d %-10.2f %-15d\n", str.ljust(40, '.'), t, (PER_TRIAL / t), u, PER_TRIAL / u)
|
||||
end
|
||||
|
||||
def profile(str)
|
||||
@ -63,13 +69,12 @@ def benchmark(str, n, coll_name, data, create_index=false)
|
||||
coll = @db.collection(coll_name)
|
||||
coll.create_index('x') if create_index
|
||||
profile(str) do
|
||||
times = []
|
||||
GC.start
|
||||
t1 = Time.now
|
||||
tm = Benchmark::Tms.new
|
||||
td = tm.add do
|
||||
n.times { |i| yield(coll, i) }
|
||||
t2 = Time.now
|
||||
times << t2 - t1
|
||||
report(str, times.min)
|
||||
end
|
||||
report(str, td.real, td.utime)
|
||||
end
|
||||
end
|
||||
|
||||
@ -96,6 +101,9 @@ def benchmark_insert_index(desc, coll_name, data)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
print_headings
|
||||
|
||||
benchmark_insert('insert (small, no index)', 'small_none', SMALL)
|
||||
benchmark_insert('insert (medium, no index)', 'medium_none', MEDIUM)
|
||||
benchmark_insert('insert (large, no index)', 'large_none', LARGE)
|
||||
@ -136,13 +144,13 @@ def benchmark_find_all(desc, coll_name, data)
|
||||
end
|
||||
end
|
||||
|
||||
benchmark_find_all('find_all (small, no index)', 'small_none', PER_TRIAL / 2)
|
||||
benchmark_find_all('find_all (medium, no index)', 'medium_none', PER_TRIAL / 2)
|
||||
benchmark_find_all('find_all (large, no index)', 'large_none', PER_TRIAL / 2)
|
||||
benchmark_find_all('find (small, no index)', 'small_none', PER_TRIAL / 2)
|
||||
benchmark_find_all('find (medium, no index)', 'medium_none', PER_TRIAL / 2)
|
||||
benchmark_find_all('find (large, no index)', 'large_none', PER_TRIAL / 2)
|
||||
|
||||
benchmark_find_all('find_all (small, indexed)', 'small_indexed', PER_TRIAL / 2)
|
||||
benchmark_find_all('find_all (medium, indexed)', 'medium_indexed', PER_TRIAL / 2)
|
||||
benchmark_find_all('find_all (large, indexed)', 'large_indexed', PER_TRIAL / 2)
|
||||
benchmark_find_all('find (small, indexed)', 'small_indexed', PER_TRIAL / 2)
|
||||
benchmark_find_all('find (medium, indexed)', 'medium_indexed', PER_TRIAL / 2)
|
||||
benchmark_find_all('find (large, indexed)', 'large_indexed', PER_TRIAL / 2)
|
||||
|
||||
benchmark_find_all('find_range (small, indexed)', 'small_indexed',
|
||||
{"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
|
||||
|
Loading…
Reference in New Issue
Block a user