Skip to content

Instantly share code, notes, and snippets.

@maceto
Last active September 3, 2015 01:42
Show Gist options
  • Save maceto/b8409e7aad3c767426a6 to your computer and use it in GitHub Desktop.
Save maceto/b8409e7aad3c767426a6 to your computer and use it in GitHub Desktop.
Benchmark on MongoDB with ORM MongoID
require 'benchmark/ips'
# Counting of records with ORM or directly on MongoDB
#
# IncomingCall.where(:created_at.gte =>(Date.today-30)).count
#
# VS
#
# db[:incoming_calls].aggregate([
# { "$match": { created_at: {"$gte": (Date.today-30)} } },
# { "$group":{ _id: "$incoming_call_id", "count": {"$sum":1}} }
# ])
ips | { |x| x.report("directo"){db[:incoming_calls].aggregate([ { "$match": { created_at: {"$gte": (Date.today-30)} } },{ "$group":{ _id: "$incoming_call_id", "count": {"$sum":1}} } ])};x.report("ORM"){ IncomingCall.where(:created_at.gte =>(Date.today-30)).count };x.compare!}
Calculating -------------------------------------
directo 153.000 i/100ms
ORM 143.000 i/100ms
-------------------------------------------------
directo 1.527k (± 4.1%) i/s - 7.650k
ORM 1.348k (±11.4%) i/s - 6.721k
Comparison:
directo: 1526.6 i/s
ORM: 1348.1 i/s - 1.13x slower
#
# END
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment