On Jan 27, 2011, at 12:55 PM, klochner wrote: > sorry for the cross-post from RoR, but I actually think this is more > of a ruby question. > > 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_f > 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_m > 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. Not every runtime we behave the same. You didn't mention which Ruby runtime you are using (MRI 1.8.x, MRI 1.9.x, JRuby 1.?, Rubinius, etc.). No one can even start to answer your question without knowing the Ruby you are using. Secondly, the Ruby code examples you pointed to aren't even necessarily testing what you think they are. The "iterative" and "functional" examples are probably a test of how fast the runtime can yield a block, or iterate a range, or any number of things. I wouldn't use that code to extrapolate any larger meaning about runtime performance. cr