Created
October 15, 2009 01:37
-
-
Save seancribbs/210562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'rubygems' | |
require 'mongo' | |
require 'mongo_ext/cbson' | |
SMALL_DOC = {} | |
MEDIUM_DOC = {"integer" => 5, "number" => 5.05, "boolean" => false, "array" => %w{test benchmark}} | |
LARGE_DOC = { | |
"base_url" => "http://www.example.com/test-me", | |
"total_word_count" => 6743, | |
"access_time" => Time.now.utc, | |
"meta_tags" => { | |
"description" => "i am a long description string", | |
"author" => "Holly Man", | |
"dynamically_created_meta_tag" => "who know\n what" | |
}, | |
"page_structure" => { | |
"counted_tags" => 3450, | |
"no_of_js_attached" => 10, | |
"no_of_images" => 6 | |
}, | |
"harvested_words" => ["10gen","web","open","source","application","paas", | |
"platform-as-a-service","technology","helps", | |
"developers","focus","building","mongodb","mongo"]*20 | |
} | |
DOCS = { 'small' => SMALL_DOC, 'medium' => MEDIUM_DOC, 'large' => LARGE_DOC } | |
connection = Mongo::Connection.new('localhost', Mongo::Connection::DEFAULT_PORT) | |
connection.drop_database('ruby-benchmark') | |
db = connection.db('ruby-benchmark') | |
BATCH_SIZE = 100 | |
PER_TRIAL = 1500 | |
# Benchmark.bmbm do |results| | |
# %w{no-index index}.each do |index| | |
# DOCS.each do |size, base_doc| | |
# coll = db.collection("#{size}-#{index}") | |
# coll.create_index({"x" => Mongo::ASCENDING}) if index == 'index' | |
# results.report("#{size}, #{index}") { | |
# (PER_TRIAL / BATCH_SIZE).times do |i| | |
# docs = [] | |
# BATCH_SIZE.times do |j| | |
# doc = base_doc.dup | |
# doc['x'] = (i*BATCH_SIZE) + j + 1 | |
# docs << doc | |
# end | |
# coll.insert(docs) | |
# end | |
# } | |
# end | |
# end | |
# end | |
require 'ruby-prof' | |
# Profile the code | |
coll = db.collection('ruby-prof') | |
result = RubyProf.profile do | |
DOCS.each do |size, base_doc| | |
BATCH_SIZE.times do |i| | |
doc = base_doc.dup | |
doc['x'] = i+1 | |
coll.insert(doc) | |
end | |
end | |
end | |
# Print a graph profile to text | |
printer = RubyProf::GraphHtmlPrinter.new(result) | |
File.open('mongobench.html', 'w') do |f| | |
printer.print(f, :min_percent => 5) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment