Skip to content

Instantly share code, notes, and snippets.

@nobu
Created November 24, 2016 06:18
Show Gist options
  • Save nobu/3315f8e9f6073221e3311828b3bd9631 to your computer and use it in GitHub Desktop.
Save nobu/3315f8e9f6073221e3311828b3bd9631 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