Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 20145 - Random unittest failures in std.datetime.stopwatch #7186

Merged
merged 1 commit into from Sep 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions std/datetime/stopwatch.d
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,14 @@ Duration[fun.length] benchmark(fun...)(uint n)
if (getpid == 1) // never happens, but prevents optimization
printf("%p", &b);
}

auto sw = StopWatch(AutoStart.yes);
auto r = benchmark!(f0, f1)(1000);
auto total = sw.peek();
assert(r[0] >= Duration.zero);
assert(r[1] > Duration.zero);
assert(r[1] > r[0]);
assert(r[0] < seconds(1));
assert(r[1] < seconds(1));
assert(r[1] >= Duration.zero);
assert(r[0] <= total);
assert(r[1] <= total);
}

@safe nothrow @nogc unittest
Expand Down