Consider,
-------------
import std.stdio;
import std.datetime;
import std.conv : to;
import std.algorithm;
import std.range : iota;
import std.array : array;
import std.random;
enum array_size = 6_000_000;
double[] some_array;
auto sortTest()
{
some_sort(some_array);
}
void main()
{
// data construction
foreach (i; 0 .. array_size)
some_array ~= uniform(0.0, 10000.0);
// benchmark
auto r = benchmark!(sortTest)(1);
auto random_result = to!Duration(r[0]);
}
-------------
This benchmark cannot be run more than once because some_sort has side effects. This loses the averaging that you can get to get rid of outliers by running benchmarks several thousand times. If benchmark had some option to pass a teardown function that would be called at the end of every test, then this could be run many times.
Comment #1 by robert.schadek — 2024-12-01T16:25:48Z