From: ts Date: 2005-06-20T22:23:49+09:00 Subject: Re: x==1 vs 1==x >>>>> "G" == Gavin Kistner writes: G> p x, x.class uln% diff -u b.rb~ b.rb --- b.rb~ 2005-06-20 15:16:51.990598152 +0200 +++ b.rb 2005-06-20 15:17:40.826174016 +0200 @@ -3,8 +3,8 @@ n = 100_000 x = rand( 10 ) p x, x.class -Benchmark.bmbm(10){ |x| - x.report('case'){ +Benchmark.bmbm(10){ |xx| + xx.report('case'){ n.times{ case x when 0 : 0 @@ -20,7 +20,7 @@ end } } - x.report('if x==n'){ + xx.report('if x==n'){ n.times{ if x==0 0 @@ -46,7 +46,7 @@ } } - x.report('if n==x'){ + xx.report('if n==x'){ n.times{ if 0==x 0 uln% uln% ruby b.rb 7 Fixnum Rehearsal --------------------------------------------- case 0.170000 0.000000 0.170000 ( 0.179179) if x==n 0.190000 0.010000 0.200000 ( 0.194086) if n==x 0.190000 0.000000 0.190000 ( 0.191561) ------------------------------------ total: 0.560000sec user system total real case 0.160000 0.020000 0.180000 ( 0.180628) if x==n 0.190000 0.010000 0.200000 ( 0.195471) if n==x 0.190000 0.010000 0.200000 ( 0.193239) uln% Guy Decoux