They say Ruby is slow...
-
@adamb said:
Strength Reduction is the transformation that would turn these loops into do_nothing loops.
Yes, but that's for really sharp compilers. I was just expecting
func( 1.0 + 2.0 )
to be turned intofunc( 3.0 )
. -
Revisiting this on the computer I use at work - which is similar to what I used in the first post:
t=Time.now; 1000000.times { 1.0 }; puts Time.now - t 0.109 nil t=Time.now; 1000000.times { 1.0 + 2.0 }; puts Time.now - t 0.515 nil t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 }; puts Time.now - t 0.873 nil t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 }; puts Time.now - t 1.264 nil t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 + 5.0 }; puts Time.now - t 1.638 nil
Which aligns better with what others have posted. My initial results in the first post seem to be an abnormality. But there is still significant performance hit.
-
why don't we just start discussing Lua while we're at it?
no, but seriously
Python is just a different language. I learned to use it before ruby, but then I discovered ruby, which I prefer for many reasons other than it's speed, which as mentioned is slow. Yes compulsory indentation is nice in some respects, but it is a complete and utter pain when mixing tabs with spaces (can't see where the problem is). Ruby allows for more creative formatting of the code (which can be very nice). I like them both, and don't we all wish the best of both could be combined?
Advertisement