Skip to content

Commit

Permalink
benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
andralex committed Sep 10, 2011
2 parents 0b6459d + 72b812a commit c149475
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
31 changes: 19 additions & 12 deletions std/benchmark.d
Expand Up @@ -7,13 +7,8 @@
Source: $(PHOBOSSRC std/_benchmark.d)
*/
module std.benchmark;
import std.algorithm, std.array, std.conv, std.datetime,
std.functional, std.traits, std.typecons;
import core.exception;

//==============================================================================
// Section with StopWatch and Benchmark Code.
//==============================================================================
import std.array, std.datetime, std.stdio, std.traits, std.typecons;
version(unittest) import std.conv;

/++
Used by StopWatch to indicate whether it should start immediately upon
Expand Down Expand Up @@ -171,6 +166,7 @@ public:

@safe unittest
{
import core.exception;
StopWatch sw;
sw.start();
auto t1 = sw.peek();
Expand All @@ -197,6 +193,7 @@ public:

@safe unittest
{
import core.exception;
StopWatch sw;
sw.start();
sw.stop();
Expand Down Expand Up @@ -266,7 +263,7 @@ private:
TickDuration _timeMeasured;
}


__EOF__
// workaround for bug4886
@safe size_t lengthof(aliases...)() pure nothrow
{
Expand Down Expand Up @@ -515,7 +512,7 @@ void benchmark_append_builtin(uint n)
void benchmark_append_appender(uint n)
{
auto s = appender!string();
auto a = appender!string();
foreach (i; 0 .. n)
{
put(a, 'x');
Expand Down Expand Up @@ -557,6 +554,8 @@ $(D append_builtin)'s speed).
*/
void benchmarkModule(string mod)(File target = stdout)
{
import std.algorithm;

struct TestResult
{
string name;
Expand Down Expand Up @@ -660,8 +659,8 @@ void benchmarkModule(string mod)(File target = stdout)
if (results.length)
{
target.writeln(
"========================================================="
"======================");
"========================================================="
"======================");
}
}

Expand Down Expand Up @@ -709,7 +708,13 @@ version(StdRunBenchmarks)
{
benchmarkModule!"std.benchmark"();
}
}

unittest
{
// Make sure this compiles
if (false) benchmarkModule!"std.benchmark"();
version(StdRunBenchmarks) benchmarkModule!"std.benchmark"();
}

// One benchmark stopwatch
private StopWatch theStopWatch;
Expand Down Expand Up @@ -916,6 +921,7 @@ else
{
struct Result
{
import std.functional;
private StopWatch _sw = void;
this(AutoStart as)
{
Expand All @@ -934,6 +940,7 @@ else
{
struct Result
{
import std.functional;
private StopWatch _sw = void;
this(AutoStart as)
{
Expand Down
1 change: 1 addition & 0 deletions std/datetime.d
Expand Up @@ -106,6 +106,7 @@ import core.stdc.time;

import std.array;
import std.algorithm;
import std.benchmark;
import std.conv;
import std.ctype;
import std.exception;
Expand Down

0 comments on commit c149475

Please sign in to comment.