From: Alexandru Popescu Date: 2006-07-14T03:09:17+09:00 Subject: Re: Recursion and Ruby (stupid question): what have you used to parse the code and show the nodes? ./alex -- .w( the_mindstorm )p. On 7/13/06, Dominik Bathon wrote: > On Thu, 13 Jul 2006 15:35:33 +0200, Erik Veenstra > wrote: > > >> > ---------------------------------------------------------------- > >> > > >> > 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: > > > > Well, _finally_ the AST is the same. But somehow, it's > > slower... Maybe the translation from source/syntax to AST is > > slower? > > > > The numbers don't lie. They are averages of 3 test runs, with a > > standard deviation of almost zero. (see below for the full > > results.) > > Indeed you are right, I forgot the newline nodes: > > >> pp < true) > if a > b > else > c > end > code > [:newline, > {:next=> > [:if, > {:body=>[:newline, {:next=>[:vcall, {:mid=>:b}]}], > :else=>[:newline, {:next=>[:vcall, {:mid=>:c}]}], > :cond=>[:vcall, {:mid=>:a}]}]}] > => nil > > vs. > > >> pp "a ? b : c".parse_to_nodes.transform(:keep_newline_nodes => true) > [:newline, > {:next=> > [:if, > {:body=>[:vcall, {:mid=>:b}], > :else=>[:vcall, {:mid=>:c}], > :cond=>[:vcall, {:mid=>:a}]}]}] > => nil > > The newline nodes are basically no-ops but they still slow things down a > bit. > > In Ruby 1.9 there are no more newline nodes, so there it really is > equivalent. > > Dominik > >