------art_69190_21183561.1171304764313
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 2/12/07, Robert Dober <robert.dober / gmail.com> wrote:
here goes the benchmark ( I was right, too bad you'll never know if I
cheated;)

the difference is only small. I think that I was wrong 'cause I really
thought that look ahead will be a killer for backtracking purpose (but I
guess it will backtrack about 1.5 times on average). Yet the reverse**2
seems a little bit faster but no need to chose one of the two algorithms for
speed :)

robert@PC:~/log/ruby/quiz/113_bis 19:20:41
521/21 > cat bench.rb
  require 'benchmark'

    array  1..100000).map { rand * (ARGV.first||1_000_000).to_f }

def phrogz quiz
  i,fiz.to_s.split('.'); i.gsub(/(\d)(?
{3}+$)/,'\\1,') + (f ?
('.'+f) : '')
end
def james quiz
  quiz.to_s.reverse.gsub(/(\d\d\d)(?
)(?!\d*\.)/,"\\1,").reverse
end


    Benchmark.bmbm do |x|
      x.report("Phrogz") {array.map{ |e| phrogz(e) }}
      x.report("James")  {array.map{ |e| james(e) }}
    end

robert@PC:~/log/ruby/quiz/113_bis 19:21:07
522/22 > ruby bench.rb 1_000_000
Rehearsal ------------------------------------------
Phrogz   7.140000   0.000000   7.140000 (  7.148000)
James    6.422000   0.000000   6.422000 (  6.452000)
-------------------------------- total: 13.562000sec

             user     system      total        real
Phrogz   7.062000   0.000000   7.062000 (  7.056000)
James    6.359000   0.000000   6.359000 (  6.385000)
robert@PC:~/log/ruby/quiz/113_bis 19:21:47
523/23 > ruby bench.rb 1_000_000_000
Rehearsal ------------------------------------------
Phrogz   7.609000   0.000000   7.609000 (  7.614000)
James    6.312000   0.000000   6.312000 (  6.308000)
-------------------------------- total: 13.921000sec

             user     system      total        real
Phrogz   7.484000   0.000000   7.484000 (  7.506000)
James    6.219000   0.000000   6.219000 (  6.268000)

Cheers
Robert

-- 
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important
things.
-Anonymous

------art_69190_21183561.1171304764313--