Skip to content

Commit

Permalink
benchsort.d - Print hash of sorted array; Used for testing purposes, …
Browse files Browse the repository at this point in the history
…it confirms the range was sorted correctly.
  • Loading branch information
Xinok committed Jun 6, 2012
1 parent f33059a commit ada3df0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions benchsort.d
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
module benchsort;
import std.stdio, std.random, std.datetime, std.array, std.string, std.range, std.algorithm;
import std.stdio, std.random, std.datetime, std.string, std.range, std.algorithm, std.md5;
import combsort, forwardsort, heapsort, insertionsort, mergesort, shellsort, stablesort, timsort, unstablesort;

void profileSort(string name, ulong bench, ulong count)
{
string tmp = format(bench, "ms");
tmp ~= std.array.replicate(" ", 10 - tmp.length);
writeln(name, std.array.replicate(" ", 40 - name.length), tmp, count);
}

void main()
{
// Initialize test array
Expand All @@ -21,6 +14,18 @@ void main()
static uint[] copy;
copy.length = base.length;

static void profileSort(string name, ulong bench, ulong count)
{
immutable blank = " ";

name = (name ~ blank)[0..40];
string time = (format(bench, "ms") ~ blank)[0..10];
string comps = (format(count) ~ blank)[0..12];
string hash = getDigestString(copy)[0..8];

writeln(name, time, comps, hash);
}

// Print information
writeln(__VENDOR__, " ", __VERSION__);
writeln(typeid(base).toString, " * ", base.length);
Expand Down Expand Up @@ -98,5 +103,5 @@ void main()
profileSort("Unstable Sort (Concurrent)", bench(unstableSort(copy, true)), comps);

profileSort("Phobos Sort Unstable", bench(sort(copy)), count(sort!pred(copy)));
profileSort("Phobos Sort Stable", bench(sort!("a < b", SwapStrategy.stable)(copy)), count(sort!(pred, SwapStrategy.stable)(copy)));
profileSort("Phobos Sort Stable (Broken)", bench(sort!("a < b", SwapStrategy.stable)(copy)), count(sort!(pred, SwapStrategy.stable)(copy)));
}

0 comments on commit ada3df0

Please sign in to comment.