www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15559] New: std.datetime.benchmark should offer a tear down

https://issues.dlang.org/show_bug.cgi?id=15559

          Issue ID: 15559
           Summary: std.datetime.benchmark should offer a tear down option
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: jack jackstouffer.com

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.

--
Jan 12