Re: sorting by rand?
- From: Dan Zwell <dzwell@xxxxxxxxx>
- Date: Mon, 30 Apr 2007 17:01:40 +0900
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
.
- References:
- Re: sorting by rand?
- From: Peter Seebach
- Re: sorting by rand?
- Prev by Date: Re: sorting by rand?
- Next by Date: Re: how to represent Date before epoch as a integer
- Previous by thread: Re: sorting by rand?
- Next by thread: Re: problem replacing newlines in regexp
- Index(es):