diff options
author | lloyd <[email protected]> | 2008-10-22 06:18:47 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-10-22 06:18:47 +0000 |
commit | ae84bfb0abbf2e184bfcfa61bc96650b6fd4a041 (patch) | |
tree | 5b9939a9965233eddfc3acf8006020fb5b865e67 /checks/timer.cpp | |
parent | 4baf2b9ef44790fb2b643ef2cdb4101b7be43c3b (diff) |
Avoid integer overflows in the benchmark timer code. This would lead to
bad results, especially noticable with fast algorithms and long test times.
Diffstat (limited to 'checks/timer.cpp')
-rw-r--r-- | checks/timer.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/checks/timer.cpp b/checks/timer.cpp index 8ebbcb4ce..c42aaa4b2 100644 --- a/checks/timer.cpp +++ b/checks/timer.cpp @@ -33,13 +33,18 @@ std::ostream& operator<<(std::ostream& out, Timer& timer) { //out << timer.value() << " "; - int events_per_second = static_cast<int>(timer.events() / timer.seconds()); + double events_per_second_fl = + static_cast<double>(timer.events() / timer.seconds()); + + u64bit events_per_second = static_cast<u64bit>(events_per_second_fl); out << events_per_second << " " << timer.get_name() << " per second; "; + std::string op_or_ops = (timer.events() == 1) ? "op" : "ops"; + out << std::setprecision(2) << std::fixed - << timer.ms_per_event() << " ms/" << timer.get_name() - << " (" << timer.events() << " ops in " + << timer.ms_per_event() << " ms/op" + << " (" << timer.events() << " " << op_or_ops << " in " << timer.milliseconds() << " ms)"; return out; |