Created
July 1, 2012 05:41
-
-
Save plusplus/3027003 to your computer and use it in GitHub Desktop.
Very Slow MM time handling
This file contains hidden or 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
source :rubygems | |
MONGO_VERSION = '~>1.6' | |
gem 'bson', MONGO_VERSION | |
gem 'bson_ext', MONGO_VERSION | |
gem 'mongo', MONGO_VERSION | |
gem 'mongo_mapper', "0.11.1" |
This file contains hidden or 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 "rubygems" | |
require "bundler/setup" | |
require "mongo_mapper" | |
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017) | |
MongoMapper.database = "test_times" | |
puts "Bundled" | |
class NoTimes | |
include MongoMapper::Document | |
key :astring, String | |
end | |
class Times | |
include MongoMapper::Document | |
key :atime, Time | |
end | |
puts "Creating test documents" | |
[NoTimes, Times].each &:delete_all | |
1000.times do | |
NoTimes.create( astring: "A string") | |
Times.create( atime: Time.now) | |
end | |
puts "Testing retrieval" | |
def bench( message, times=10 ) | |
t = Time.now | |
times.times do | |
yield | |
end | |
puts "#{message}: #{Time.now - t}" | |
end | |
bench "NoTimes MM" do | |
NoTimes.all | |
end | |
bench "Times MM" do | |
Times.all | |
end | |
bench "NoTimes Raw" do | |
NoTimes.collection.find( {} ).map {|i| i} | |
end | |
bench "Times Raw" do | |
Times.collection.find( {} ).map {|i| i} | |
end |
This file contains hidden or 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
└─▪ ruby test.rb | |
Bundled | |
Creating test documents | |
Testing retrieval | |
NoTimes MM: 0.800193 | |
Times MM: 1.393776 | |
NoTimes Raw: 0.275042 | |
Times Raw: 0.320742 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment