OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // buildbots, some of which are VMs. These machines can run horribly | 201 // buildbots, some of which are VMs. These machines can run horribly |
202 // slow, and there is really no value for checking against a max timer. | 202 // slow, and there is really no value for checking against a max timer. |
203 //EXPECT_LT((stop - start).InMilliseconds(), kMaxTime); | 203 //EXPECT_LT((stop - start).InMilliseconds(), kMaxTime); |
204 printf("%s: %1.2fus per call\n", cases[test_case].description, | 204 printf("%s: %1.2fus per call\n", cases[test_case].description, |
205 (stop - start).InMillisecondsF() * 1000 / kLoops); | 205 (stop - start).InMillisecondsF() * 1000 / kLoops); |
206 test_case++; | 206 test_case++; |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
210 TEST(TimeTicks, Drift) { | 210 TEST(TimeTicks, Drift) { |
| 211 // If QPC is disabled, this isn't measuring anything. |
| 212 if (!TimeTicks::IsHighResClockWorking()) |
| 213 return; |
| 214 |
211 const int kIterations = 100; | 215 const int kIterations = 100; |
212 int64 total_drift = 0; | 216 int64 total_drift = 0; |
213 | 217 |
214 for (int i = 0; i < kIterations; ++i) { | 218 for (int i = 0; i < kIterations; ++i) { |
215 int64 drift_microseconds = TimeTicks::GetQPCDriftMicroseconds(); | 219 int64 drift_microseconds = TimeTicks::GetQPCDriftMicroseconds(); |
216 | 220 |
217 // Make sure the drift never exceeds our limit. | 221 // Make sure the drift never exceeds our limit. |
218 EXPECT_LT(drift_microseconds, 50000); | 222 EXPECT_LT(drift_microseconds, 50000); |
219 | 223 |
220 // Sleep for a few milliseconds (note that it means 1000 microseconds). | 224 // Sleep for a few milliseconds (note that it means 1000 microseconds). |
221 // If we check the drift too frequently, it's going to increase | 225 // If we check the drift too frequently, it's going to increase |
222 // monotonically, making our measurement less realistic. | 226 // monotonically, making our measurement less realistic. |
223 base::PlatformThread::Sleep( | 227 base::PlatformThread::Sleep( |
224 base::TimeDelta::FromMilliseconds((i % 2 == 0) ? 1 : 2)); | 228 base::TimeDelta::FromMilliseconds((i % 2 == 0) ? 1 : 2)); |
225 | 229 |
226 total_drift += drift_microseconds; | 230 total_drift += drift_microseconds; |
227 } | 231 } |
228 | 232 |
229 // Sanity check. We expect some time drift to occur, especially across | 233 // Sanity check. We expect some time drift to occur, especially across |
230 // the number of iterations we do. However, if the QPC is disabled, this | 234 // the number of iterations we do. |
231 // is not measuring anything (drift is zero in that case). | |
232 EXPECT_LT(0, total_drift); | 235 EXPECT_LT(0, total_drift); |
233 | 236 |
234 printf("average time drift in microseconds: %lld\n", | 237 printf("average time drift in microseconds: %lld\n", |
235 total_drift / kIterations); | 238 total_drift / kIterations); |
236 } | 239 } |
OLD | NEW |