Skip to content

Instantly share code, notes, and snippets.

@afeld
Last active December 18, 2015 18:30
Show Gist options
  • Save afeld/5826497 to your computer and use it in GitHub Desktop.
Save afeld/5826497 to your computer and use it in GitHub Desktop.
performance comparison of Mongoid, Moped and `mongo` shell w/ MongoDB 2.4.3
function bench(f) {
var start = new Date();
f();
var finish = new Date();
print( ((finish-start) / 1000) + 's' );
}
bench(function(){
db.users.find().limit(2000).forEach(function(user){
});
});
// 2.859s
require 'benchmark'
num_records = 2000
# Mongoid
puts Benchmark.measure {
User.limit(num_records).each do |user|
end
}
# 0.510000 0.070000 0.580000 ( 0.665689)
# Moped
puts Benchmark.measure {
User.collection.find().limit(num_records).each do |user|
end
}
# 0.480000 0.030000 0.510000 ( 0.555456)
@dblock
Copy link

dblock commented Jun 20, 2013

Isn't the first one running on the server and the second one has to copy all the data from server to client?

@durran
Copy link

durran commented Jun 21, 2013

If the first is running in the shell it's copying the data over as well from server to client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment