minor: benchmark updates

This commit is contained in:
Kyle Banker 2009-11-16 18:34:25 -05:00
parent 7445459101
commit e8748651b5
1 changed files with 34 additions and 36 deletions

View File

@ -40,8 +40,6 @@ LARGE = {
'developers','focus','building','mongodb','mongo'] * 20
}
require 'benchmark'
def report(str, t)
printf("%s%d\n", str.ljust(60, '.'), PER_TRIAL / t)
end
@ -61,14 +59,19 @@ def profile(str)
end
end
def benchmark(str, n, db, coll_name, object)
coll = db.collection(coll_name)
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
GC.start
tms = Benchmark.measure do
n.times { |i| yield(coll, object.is_a?(Hash) ? object.dup : object, i) }
times = []
TRIALS.times do
GC.start
t1 = Time.now
n.times { |i| yield(coll, i) }
t2 = Time.now
times << t2 - t1
end
report(str, tms.real)
report(str, times.min)
end
end
@ -79,18 +82,17 @@ connection = Connection.new(host, port)
connection.drop_database("benchmark")
@db = connection.db('benchmark')
def benchmark_insert(desc, data_desc, data)
benchmark(desc, PER_TRIAL, @db, data_desc, data) do |coll, object, i|
object['x'] = i
coll.insert(object)
def benchmark_insert(desc, coll_name, data)
benchmark(desc, PER_TRIAL, coll_name, data) do |coll, i|
data['x'] = i
coll.insert(data)
end
end
def benchmark_insert_index(desc, data_desc, data)
benchmark(desc, PER_TRIAL, @db, data_desc, data) do |coll, object, i|
coll.create_index('x')
object['x'] = i
coll.insert(object)
def benchmark_insert_index(desc, coll_name, data)
benchmark(desc, PER_TRIAL, coll_name, data, true) do |coll, i|
data['x'] = i
coll.insert(data)
end
end
@ -102,10 +104,10 @@ benchmark_insert_index('insert (small, index)', 'small_indexed', SMALL)
benchmark_insert_index('insert (medium, index)', 'medium_indexed', MEDIUM)
benchmark_insert_index('insert (large, index)', 'large_indexed', LARGE)
def benchmark_insert_batch(desc, data_desc, data)
benchmark(desc, PER_TRIAL / BATCH_SIZE, @db, data_desc, data) do |coll, object, i|
object['x'] = i
coll.insert([object] * BATCH_SIZE)
def benchmark_insert_batch(desc, coll_name, data)
benchmark(desc, PER_TRIAL / BATCH_SIZE, coll_name, data) do |coll, i|
data['x'] = i
coll.insert([data] * BATCH_SIZE)
end
end
@ -113,41 +115,37 @@ benchmark_insert_batch('insert batch (small, index)', 'small_bulk', SMALL)
benchmark_insert_batch('insert batch (medium, index)', 'medium_bulk', MEDIUM)
benchmark_insert_batch('insert batch (large, index)', 'large_bulk', LARGE)
def benchmark_find_one(desc, data_desc, data)
benchmark(desc, PER_TRIAL, @db, data_desc, data) do |coll, object, i|
coll.find_one('x' => data_desc)
def benchmark_find_one(desc, coll_name, data)
benchmark(desc, PER_TRIAL, coll_name, data) do |coll, i|
coll.find_one({'x' => data})
end
end
benchmark_find_one('find_one (small, no index)', 'small_none', PER_TRIAL / 2)
benchmark_find_one('find_one (medium, no index)', 'medium_none', PER_TRIAL / 2)
benchmark_find_one('find_one (large, no index)', 'large_none', PER_TRIAL / 2)
benchmark_find_one('find_one (small, indexed)', 'small_indexed', PER_TRIAL / 2)
benchmark_find_one('find_one (medium, indexed)', 'medium_indexed', PER_TRIAL / 2)
benchmark_find_one('find_one (large, indexed)', 'large_indexed', PER_TRIAL / 2)
def benchmark_find_all(desc, data_desc, data)
benchmark(desc, PER_TRIAL, @db, data_desc, data) do |coll, object, i|
coll.find('x' => data_desc).each {}
def benchmark_find_all(desc, coll_name, data)
benchmark(desc, PER_TRIAL, coll_name, data) do |coll, i|
coll.find({'x' => data}).each {|o| o}
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_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)
def benchmark_find_range(desc, data_desc, data)
benchmark(desc, PER_TRIAL, @db, data_desc, data) do |coll, object, i|
coll.find('x' => data_desc).each {}
end
end
benchmark_find_range('find_range (small, indexed)', 'small_indexed',
benchmark_find_all('find_range (small, indexed)', 'small_indexed',
{"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
benchmark_find_range('find_range (medium, indexed)', 'medium_indexed',
benchmark_find_all('find_range (medium, indexed)', 'medium_indexed',
{"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
benchmark_find_range('find_range (large, indexed)', 'large_indexed',
benchmark_find_all('find_range (large, indexed)', 'large_indexed',
{"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})