Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

benchsort.d - Print hash of sorted array; Used for testing purposes, …

…it confirms the range was sorted correctly.
  • Loading branch information...
commit ada3df0624d9f7b3889ab5e52847a70893f27c93 1 parent f33059a
@Xinok authored
Showing with 14 additions and 9 deletions.
  1. +14 −9 benchsort.d
View
23 benchsort.d
@@ -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
@@ -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);
@@ -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)));
}
Please sign in to comment.
Something went wrong with that request. Please try again.