Skip to content

Instantly share code, notes, and snippets.

@sergey-alekseev
Created March 10, 2015 20:33
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 sergey-alekseev/43ca681ae06d8d1c8c5d to your computer and use it in GitHub Desktop.
Save sergey-alekseev/43ca681ae06d8d1c8c5d to your computer and use it in GitHub Desktop.
Object comparison vs. id
Benchmark.ips do |x|
x.report('object comparison') { item.user == print.user }
x.report('id comparison') { item.user_id == print.user_id }
x.compare!
end
Calculating -------------------------------------
object comparison 1.204k i/100ms
id comparison 1.972k i/100ms
-------------------------------------------------
object comparison 43.855k (±18.9%) i/s - 209.496k
id comparison 1.077M (±21.8%) i/s - 4.727M
Comparison:
id comparison: 1076589.8 i/s
object comparison: 43854.6 i/s - 24.55x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment