Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1080)

Unified Diff: base/time_unittest.cc

Issue 4092: Change to Hi Res timers on Windows.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/time_posix.cc ('k') | base/time_unittest_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time_unittest.cc
===================================================================
--- base/time_unittest.cc (revision 2585)
+++ base/time_unittest.cc (working copy)
@@ -86,21 +86,38 @@
}
TEST(TimeTicks, Deltas) {
- TimeTicks ticks_start = TimeTicks::Now();
- PlatformThread::Sleep(10);
- TimeTicks ticks_stop = TimeTicks::Now();
- TimeDelta delta = ticks_stop - ticks_start;
- EXPECT_GE(delta.InMilliseconds(), 10);
- EXPECT_GE(delta.InMicroseconds(), 10000);
- EXPECT_EQ(delta.InSeconds(), 0);
+ for (int index = 0; index < 500; index++) {
+ TimeTicks ticks_start = TimeTicks::Now();
+ PlatformThread::Sleep(10);
+ TimeTicks ticks_stop = TimeTicks::Now();
+ TimeDelta delta = ticks_stop - ticks_start;
+ // Note: Although we asked for a 10ms sleep, if the
+ // time clock has a finer granularity than the Sleep()
+ // clock, it is quite possible to wakeup early. Here
+ // is how that works:
+ // Time(ms timer) Time(us timer)
+ // 5 5010
+ // 6 6010
+ // 7 7010
+ // 8 8010
+ // 9 9000
+ // Elapsed 4ms 3990us
+ //
+ // Unfortunately, our InMilliseconds() function truncates
+ // rather than rounds. We should consider fixing this
+ // so that our averages come out better.
+ EXPECT_GE(delta.InMilliseconds(), 9);
+ EXPECT_GE(delta.InMicroseconds(), 9000);
+ EXPECT_EQ(delta.InSeconds(), 0);
+ }
}
-TEST(TimeTicks, UnreliableHighResNow) {
- TimeTicks ticks_start = TimeTicks::UnreliableHighResNow();
+TEST(TimeTicks, HighResNow) {
+ TimeTicks ticks_start = TimeTicks::HighResNow();
PlatformThread::Sleep(10);
- TimeTicks ticks_stop = TimeTicks::UnreliableHighResNow();
+ TimeTicks ticks_stop = TimeTicks::HighResNow();
TimeDelta delta = ticks_stop - ticks_start;
- EXPECT_GE(delta.InMilliseconds(), 10);
+ EXPECT_GE(delta.InMicroseconds(), 9000);
}
TEST(TimeDelta, FromAndIn) {
« no previous file with comments | « base/time_posix.cc ('k') | base/time_unittest_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698