Skip to content

Instantly share code, notes, and snippets.

@mgiagante
Created September 16, 2016 04:14
Show Gist options
  • Save mgiagante/bba68313c24f5eae8085d8b2b7e0dc7e to your computer and use it in GitHub Desktop.
Save mgiagante/bba68313c24f5eae8085d8b2b7e0dc7e to your computer and use it in GitHub Desktop.
require 'benchmark'
executions = 100_000_000
Benchmark.bm do |conditional_assignment|
conditional_assignment.report { executions.times do a ||= 1; end }
conditional_assignment.report { executions.times do a = a || 1; end }
end
=begin
user system total real
9.110000 0.000000 9.110000 ( 9.112874)
9.150000 0.000000 9.150000 ( 9.152972)
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment