in reply to Re: Returning the lowest key in a hash (or highest)
in thread Returning the lowest key in a hash (or highest)
Sort takes O(n log n). Simply walking the keys of the hash is only O(n).A lot of people made this point, but I wonder if it's really as important as people think. sort() is written in C and is very fast. Walking the keys requires that a lot of Perl opcodes must be dispatched, so it is probably a lot slower. Yes, the times are O(n log n) and O(n), but that ignores the constant factors, and I would expect the constant factor for the sort to be much smaller, so that the sort would be faster except for extremely large hashes.
Maybe someone who likes benchmarking can look into this and post the results.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Benchmarking hash sort vs. walk (Was: Re: Re: Returning the lowest key in a hash (or highest))
by larryl (Monk) on Mar 26, 2001 at 01:03 UTC |