Skip to content

Instantly share code, notes, and snippets.

@seancribbs
Created October 16, 2009 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seancribbs/211853 to your computer and use it in GitHub Desktop.
Save seancribbs/211853 to your computer and use it in GitHub Desktop.
The C oid generation uses bare C types and casting to get around the pack/unpack inefficiencies.
Here's 100_000.times { Mongo::ObjectID.new } with each algorithm (using Benchmark.bmbm).
Rehearsal --------------------------------------------
Ruby oid 2.610000 0.350000 2.960000 ( 2.976763)
C oid 0.950000 0.300000 1.250000 ( 1.251934)
----------------------------------- total: 4.210000sec
user system total real
Ruby oid 2.710000 0.330000 3.040000 ( 3.063867)
C oid 0.920000 0.300000 1.220000 ( 1.230964)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment