Thanks for the reply. I've not used the Schwarztian Transform before so tend to shy away from it. However, I read a bit more about it and discovered that it won't work for my actual code which is an array of objects.
Your bucketsort is the elegant solution that I was seeking. Interesting though it's about twice as slow as my ugly version as indicated by this benchmark:
Benchmark: timing 500000 iterations of bucketsort, sort...
bucketsort: 2 wallclock secs ( 1.72 usr + 0.00 sys = 1.72 CPU) @ 29
+0697.67/s (n=500000)
sort: 0 wallclock secs ( 0.89 usr + 0.00 sys = 0.89 CPU) @ 56
+1797.75/s (n=500000)
Rate bucketsort sort
bucketsort 290698/s -- -48%
sort 561798/s 93% --
Thanks
-Wm
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|