Skip to content

Commit

Permalink
Merge pull request #6139 from n8sh/issue-18398-stopwatch-doc
Browse files Browse the repository at this point in the history
Issue 18398 - std.datetime.stopwatch documented examples could be better
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
  • Loading branch information
dlang-bot committed Feb 9, 2018
2 parents 4933e91 + 602c3ed commit 7c1e10d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions std/datetime/stopwatch.d
Expand Up @@ -82,6 +82,22 @@ struct StopWatch
{
public:

/// Measure a time in milliseconds, microseconds, or nanoseconds
@safe nothrow @nogc unittest
{
auto sw = StopWatch(AutoStart.no);
sw.start();
// ... Insert operations to be timed here ...
sw.stop();

long msecs = sw.peek.total!"msecs";
long usecs = sw.peek.total!"usecs";
long nsecs = sw.peek.total!"nsecs";

assert(usecs >= msecs * 1000);
assert(nsecs >= usecs * 1000);
}

///
@system nothrow @nogc unittest
{
Expand Down

0 comments on commit 7c1e10d

Please sign in to comment.