From: Dan Zwell Date: 2007-04-30T17:01:40+09:00 Subject: Re: sorting by rand? Peter Seebach wrote: >> Or perhaps because I >> have more method calls, as I made a method Array#randomize! (that calls >> Array#swap! n times) > > That might well do it; method lookup is comparatively expensive, I > think. > > ... Of course, the entire thing is probably silly, in that I doubt most > programs spend much time unsorting arrays. I was mostly just curious > about the question of what happens if you try to provide an un-fixed > sort key. For sort_by, they're cached; sort { rand <=> rand } might > be unpredictable, though. > That did it--I replaced calls to swap!() with three lines of code, and now my algorithm is faster on arrays with as little as 40 elements! Dan