diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-26 03:00:00 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-26 03:00:00 +0000 |
commit | de592d31b3e82b1ff938c46f3db8cb06a716062e (patch) | |
tree | 32af531b478fabff890ca7b7dee71ffccf744048 /base/time_unittest.cc | |
parent | f5e3da4d564980a048f375cf1a824a01df03382a (diff) | |
download | chromium_src-de592d31b3e82b1ff938c46f3db8cb06a716062e.zip chromium_src-de592d31b3e82b1ff938c46f3db8cb06a716062e.tar.gz chromium_src-de592d31b3e82b1ff938c46f3db8cb06a716062e.tar.bz2 |
Change to Hi Res timers on Windows.
There are two parts of this:
1) TimeTicks:Now()
Don't call timeBeginPeriod() in all cases.
Use the new SystemMonitor class to watch battery on/off
transitions and use the timeBeginPeriod() only when we're
using the battery.
2) TimeTicks::UnreliableHiResNow()
Change this function from "UnreliableHiResNow()" to
"HiResNow()". We still use QPC, but we detect if we're
on AMD Athlon XP machines which fail on QPC. For those
systems, we fall back to TimeTicks::Now().
Updated tests to detect hardware specifics of timers.
Output of the test will contain lines such as these:
[ RUN ] TimeTicks.SubMillisecondTimers
Min timer is: 1us
[ OK ] TimeTicks.SubMillisecondTimers
[ RUN ] TimeTicks.TimeGetTimeCaps
timeGetTime range is 1 to 1000000ms
[ OK ] TimeTicks.TimeGetTimeCaps
[ RUN ] TimeTicks.QueryPerformanceFrequency
QueryPerformanceFrequency is 2394.18MHz
[ OK ] TimeTicks.QueryPerformanceFrequency
[ RUN ] TimeTicks.TimerPerformance
Time::Now: 0.11us per call
TimeTicks::Now: 0.09us per call
TimeTicks::HighResNow: 0.26us per call
[ OK ] TimeTicks.TimerPerformance
Review URL: http://codereview.chromium.org/4092
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time_unittest.cc')
-rw-r--r-- | base/time_unittest.cc | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/base/time_unittest.cc b/base/time_unittest.cc index 039913b..db0990f4 100644 --- a/base/time_unittest.cc +++ b/base/time_unittest.cc @@ -86,21 +86,38 @@ TEST(Time, LocalMidnight) { } 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) { |