Sorting algorithms benchmark
Stewart Gordon
smjg_1998 at yahoo.com
Wed Mar 7 08:34:04 PST 2007
Deewiant Wrote:
<snip>
> That's exactly what's confusing me. I suppose the reason you
> need that call is that you're not counting the number of swaps
> made in the loop, and you're stopping just when the gap is 1,
> not when swaps are also zero. Which I think makes the
> algorithm a bit different, since the number of "combs" you do
> is limited to once per gap size, plus the one bubble sort
> after you're done.
It's more the other way round - calling bubble sort is the way I chose to implement the passes of gap size 1. It saves having to maintain a swap flag during the passes of gap > 1.
> I added my comb sort 11 implementation to your benchmark, and
> it's noticeably faster for random data than your comb sort, at
> least on my machine. So something's different, to be sure.
> Even without the optimization related to gap size 11, mine is
> faster.
<snip>
That appears to be because you've implemented the optimum shrink factor. If I change my implementation to use it as well, it runs at about the same speed as yours.
Stewart.
More information about the Digitalmars-d-announce
mailing list