From: Dominik Bathon Date: 2006-07-13T19:12:22+09:00 Subject: Re: Recursion and Ruby On Thu, 13 Jul 2006 10:57:29 +0200, Erik Veenstra wrote: > You could use "case" as well (see version 2). It's faster. > Using an ordinary if..else (without the elsif part) is faster > (see version 3). And version 4 is once again faster. > > 4 is faster than 3 is faster than 2 is faster than 1... > > gegroet, > Erik V. - http://www.erikveen.dds.nl/ > > ---------------------------------------------------------------- > > Version 1 100,0% > Version 2 90,3% > Version 3 72,7% > Version 4 70,2% > > ---------------------------------------------------------------- Actually version 3 and version 4 are exactly equivalent for Ruby, it parses them both as NODE_IF: >> pp "if a; b; else; c; end".parse_to_nodes.transform [:if, {:body=>[:vcall, {:mid=>:b}], :else=>[:vcall, {:mid=>:c}], :cond=>[:vcall, {:mid=>:a}]}] => nil >> pp "a ? b : c".parse_to_nodes.transform [:if, {:body=>[:vcall, {:mid=>:b}], :else=>[:vcall, {:mid=>:c}], :cond=>[:vcall, {:mid=>:a}]}] => nil Dominik