From: Ed Howland Date: 2005-11-24T08:27:24+09:00 Subject: Re: How convert an integer to a bit array On 11/23/05, Daniel Sheppard wrote: > Integer#[] 8 times > Array.new once > > Integer#@- 8 times > Integer#+ 8 times > Integer#- 8 times > > Once again, those extra calls take longer than the single call to > Array#reverse!. > > It's an easy trap to fall into - experience in most other languages > teaches you that simple operations on primitives are much faster than > calling of to a method. The problem with porting that knowledge to ruby > is that there are not operations on primitives - everything is going > through the method dispatching. > .... I saw that you were right. I used require 'benchmark' and 100,000 and 1M size arrays. I guess I was assuming, as you say, that my optimization to primative operations ((-), and +) would be faster, but in fact actually increased the amount of time in Ruby land. Thanks for the insight. What makes that great, is the knowledge that writing code the way you think about a problem, may in fact be the ultimate solution. Ed