Benchmark block

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 30 17:54:43 PDT 2015


On 3/30/15 4:29 PM, Jonathan wrote:
> I have no idea if this has been discussed yet, but I was thinking it
> would be neat to have benchmark blocks that only run when specified,
> like how unittest works.
>
> Code:
>
> benchmarks
> {
>   import std.conv : to;
>   int a;
>   void f() {auto b = to!string(a);}
>   auto r = benchmark!(f)(10_000);
>   auto f0Result = to!Duration(r[0]);
>   writeln(f0Result)
> }
>
> Example:
> rdmd -benchmarks -main myapp.d
>
> Alternatively, the writeln could be replaced with some kind of standard
> benchmark output utility (similar to the idea of assert when used for
> unit tests).
>
> Thoughts?

@kind("benchmark") unittest
{
    ...
}


Andrei


More information about the Digitalmars-d mailing list