| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 #include <process.h> | 7 #include <process.h> |
| 8 | 8 |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // Test some basic assumptions that we expect about QPC. | 156 // Test some basic assumptions that we expect about QPC. |
| 157 | 157 |
| 158 LARGE_INTEGER frequency; | 158 LARGE_INTEGER frequency; |
| 159 BOOL rv = QueryPerformanceFrequency(&frequency); | 159 BOOL rv = QueryPerformanceFrequency(&frequency); |
| 160 EXPECT_EQ(TRUE, rv); | 160 EXPECT_EQ(TRUE, rv); |
| 161 EXPECT_GT(frequency.QuadPart, 1000000); // Expect at least 1MHz | 161 EXPECT_GT(frequency.QuadPart, 1000000); // Expect at least 1MHz |
| 162 printf("QueryPerformanceFrequency is %5.2fMHz\n", | 162 printf("QueryPerformanceFrequency is %5.2fMHz\n", |
| 163 frequency.QuadPart / 1000000.0); | 163 frequency.QuadPart / 1000000.0); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TimeTicks GetTickCountTest() { |
| 167 return TimeTicks::FromInternalValue(GetTickCount64()); |
| 168 } |
| 169 |
| 170 TimeTicks RDTSCTest() { |
| 171 return TimeTicks::FromInternalValue(__rdtsc()); |
| 172 } |
| 173 |
| 174 TimeTicks TimeGetTimeTest() { |
| 175 return TimeTicks::FromInternalValue(timeGetTime()); |
| 176 } |
| 177 |
| 178 TimeTicks QPCTest() { |
| 179 LARGE_INTEGER out; |
| 180 QueryPerformanceCounter(&out); |
| 181 return TimeTicks::FromInternalValue(out.QuadPart); |
| 182 } |
| 183 |
| 166 TEST(TimeTicks, TimerPerformance) { | 184 TEST(TimeTicks, TimerPerformance) { |
| 167 // Verify that various timer mechanisms can always complete quickly. | 185 // Verify that various timer mechanisms can always complete quickly. |
| 168 // Note: This is a somewhat arbitrary test. | 186 // Note: This is a somewhat arbitrary test. |
| 169 const int kLoops = 10000; | 187 const int kLoops = 10000000; |
| 170 // Due to the fact that these run on bbots, which are horribly slow, | 188 // Due to the fact that these run on bbots, which are horribly slow, |
| 171 // we can't really make any guarantees about minimum runtime. | 189 // we can't really make any guarantees about minimum runtime. |
| 172 // Really, we want these to finish in ~10ms, and that is generous. | 190 // Really, we want these to finish in ~10ms, and that is generous. |
| 173 const int kMaxTime = 35; // Maximum acceptible milliseconds for test. | 191 const int kMaxTime = 35; // Maximum acceptible milliseconds for test. |
| 174 | 192 |
| 175 typedef TimeTicks (*TestFunc)(); | 193 typedef TimeTicks (*TestFunc)(); |
| 176 struct TestCase { | 194 struct TestCase { |
| 177 TestFunc func; | 195 TestFunc func; |
| 178 char *description; | 196 char *description; |
| 179 }; | 197 }; |
| 180 // Cheating a bit here: assumes sizeof(TimeTicks) == sizeof(Time) | 198 // Cheating a bit here: assumes sizeof(TimeTicks) == sizeof(Time) |
| 181 // in order to create a single test case list. | 199 // in order to create a single test case list. |
| 182 COMPILE_ASSERT(sizeof(TimeTicks) == sizeof(Time), | 200 COMPILE_ASSERT(sizeof(TimeTicks) == sizeof(Time), |
| 183 test_only_works_with_same_sizes); | 201 test_only_works_with_same_sizes); |
| 184 TestCase cases[] = { | 202 TestCase cases[] = { |
| 185 { reinterpret_cast<TestFunc>(Time::Now), "Time::Now" }, | 203 { reinterpret_cast<TestFunc>(Time::Now), "Time::Now" }, |
| 204 { GetTickCountTest, "GetTickCount64" }, |
| 205 { RDTSCTest, "__rdtsc" }, |
| 206 { TimeGetTimeTest, "timeGetTime" }, |
| 207 { QPCTest, "QueryPerformanceCounter" }, |
| 186 { TimeTicks::Now, "TimeTicks::Now" }, | 208 { TimeTicks::Now, "TimeTicks::Now" }, |
| 187 { TimeTicks::HighResNow, "TimeTicks::HighResNow" }, | 209 { TimeTicks::HighResNow, "TimeTicks::HighResNow" }, |
| 188 { NULL, "" } | 210 { NULL, "" } |
| 189 }; | 211 }; |
| 190 | 212 |
| 191 int test_case = 0; | 213 int test_case = 0; |
| 192 while (cases[test_case].func) { | 214 while (cases[test_case].func) { |
| 193 TimeTicks start = TimeTicks::HighResNow(); | 215 TimeTicks start = TimeTicks::HighResNow(); |
| 194 for (int index = 0; index < kLoops; index++) | 216 for (int index = 0; index < kLoops; index++) |
| 195 cases[test_case].func(); | 217 cases[test_case].func(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 total_drift += drift_microseconds; | 252 total_drift += drift_microseconds; |
| 231 } | 253 } |
| 232 | 254 |
| 233 // Sanity check. We expect some time drift to occur, especially across | 255 // Sanity check. We expect some time drift to occur, especially across |
| 234 // the number of iterations we do. | 256 // the number of iterations we do. |
| 235 EXPECT_LT(0, total_drift); | 257 EXPECT_LT(0, total_drift); |
| 236 | 258 |
| 237 printf("average time drift in microseconds: %lld\n", | 259 printf("average time drift in microseconds: %lld\n", |
| 238 total_drift / kIterations); | 260 total_drift / kIterations); |
| 239 } | 261 } |
| OLD | NEW |