On Jan 27, 1:29 pm, klochner
<kloch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I got sidetracked while benchmarking ruby factorial
code:http://rosettacode.org/wiki/Factorial#Ruby
>
> I put all that code into test_fact.rb and ran with:
>
> > ruby test_fact.rb
> > rails runner test_fact.rb #from a fresh rails app
> > rails runner test_fact.rb #from a mature rails app
>
> here are the respective results:
>
> user system total real #ruby
> recursive: 8.660000 0.040000 8.700000 ( 8.888191)
> iterative: 6.770000 0.030000 6.800000 ( 6.892491)
> functional: 6.240000 0.030000 6.270000 ( 6.334801)
>
> user system total real # rails
> runner fresh
> recursive: 10.140000 0.070000 10.210000 ( 10.760008)
> iterative: 8.750000 0.050000 8.800000 ( 9.050677)
> functional: 8.200000 0.040000 8.240000 ( 8.477966)
>
> user system total real #rails runner
> mature
> recursive: 17.400000 0.170000 17.570000 ( 17.792121)
> iterative: 15.730000 0.140000 15.870000 ( 16.233311)
> functional: 15.450000 0.160000 15.610000 ( 16.245557)
>
> I profiled it as well and the function calls were identical, just
> slower.
>
> This feels like a ruby issue that rails brings out in spades, I''m
> wondering if anyone here has some insight as to what''s going on.
I tried this with the * above changed to +, and the results were
radically different - the plain Ruby and runner versions got identical
results (+/- about 0.01 s). That makes me wonder if there''s something
weird with BigInteger/BigDecimal, given that the sum version only
yields 80201 while the factorial is
64034522846623895262347970319503005850702583026002959458684445942802397169186831436278478647463264676294350575035856810848298162883517435228961988646802997937341654150838162426461942352307046244325015114448670890662773914918117331955996440709549671345290477020322434911210797593280795101545372667251627877890009349763765710326350331533965349868386831339352024373788157786791506311858702618270169819740062983025308591298346162272304558339520759611505302236086810433297255194852674432232438669948422404232599805551610635942376961399231917134063858996537970147827206606320217379472010321356624613809077942304597360699567595836096158715129913822286578579549361617654480453222007825818400848436415591229454275384803558374518022675900061399560145595206127211192918105032491008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.
--Matt Jones
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.