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