Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save suzukaze/b9ae68f30a47cc23ab935e2389bc8778 to your computer and use it in GitHub Desktop.
Save suzukaze/b9ae68f30a47cc23ab935e2389bc8778 to your computer and use it in GitHub Desktop.
benchmark of if and &.
$ ruby -rbenchmark -e 'N=1000_000;a=self;Benchmark.bm{|x| x.report("if") {N.times{a.itself if a}}; x.report("&.") {N.times{a&.itself}}}'
user system total real
if 0.060000 0.010000 0.070000 ( 0.076417)
&. 0.060000 0.000000 0.060000 ( 0.072385)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment