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 | |
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')
-rw-r--r-- | checks/timer.cpp | 11 | ||||
-rw-r--r-- | checks/timer.h | 4 |
2 files changed, 10 insertions, 5 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; diff --git a/checks/timer.h b/checks/timer.h index 4bdc08154..48d6b6805 100644 --- a/checks/timer.h +++ b/checks/timer.h @@ -27,12 +27,12 @@ class Timer double ms_per_event() { return milliseconds() / events(); } double seconds_per_event() { return seconds() / events(); } - u32bit events() const { return event_count * event_mult; } + u64bit events() const { return event_count * event_mult; } std::string get_name() const { return name; } private: std::string name; u64bit time_used, timer_start; - u32bit event_count, event_mult; + u64bit event_count, event_mult; }; inline bool operator<(const Timer& x, const Timer& y) |