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

Side by Side Diff: base/time/time_win_unittest.cc

Issue 429743002: Make QPCValueToMicroseconds faster in case the value is less than 44 bits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add one more test for exactly qpc_value is the threshold Created 6 years, 4 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 unified diff | Download patch
« no previous file with comments | « base/time/time_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 total_drift += drift_microseconds; 234 total_drift += drift_microseconds;
235 } 235 }
236 236
237 // Sanity check. We expect some time drift to occur, especially across 237 // Sanity check. We expect some time drift to occur, especially across
238 // the number of iterations we do. 238 // the number of iterations we do.
239 EXPECT_LT(0, total_drift); 239 EXPECT_LT(0, total_drift);
240 240
241 printf("average time drift in microseconds: %lld\n", 241 printf("average time drift in microseconds: %lld\n",
242 total_drift / kIterations); 242 total_drift / kIterations);
243 } 243 }
244
245 int64 QPCValueToMicrosecondsSafely(LONGLONG qpc_value,
246 int64 ticks_per_second) {
247 int64 whole_seconds = qpc_value / ticks_per_second;
248 int64 leftover_ticks = qpc_value % ticks_per_second;
249 int64 microseconds = (whole_seconds * Time::kMicrosecondsPerSecond) +
250 ((leftover_ticks * Time::kMicrosecondsPerSecond) /
251 ticks_per_second);
252 return microseconds;
253 }
254
255 TEST(TimeTicks, FromQPCValue) {
256 if (!TimeTicks::IsHighResClockWorking())
257 return;
258 LARGE_INTEGER frequency;
259 QueryPerformanceFrequency(&frequency);
260 int64 ticks_per_second = frequency.QuadPart;
261 LONGLONG qpc_value = Time::kQPCOverflowThreshold;
262 TimeTicks expected_value = TimeTicks::FromInternalValue(
263 QPCValueToMicrosecondsSafely(qpc_value + 1, ticks_per_second));
264 EXPECT_EQ(expected_value,
265 TimeTicks::FromQPCValue(qpc_value + 1));
266 expected_value = TimeTicks::FromInternalValue(
267 QPCValueToMicrosecondsSafely(qpc_value, ticks_per_second));
268 EXPECT_EQ(expected_value,
269 TimeTicks::FromQPCValue(qpc_value));
270 expected_value = TimeTicks::FromInternalValue(
271 QPCValueToMicrosecondsSafely(qpc_value - 1, ticks_per_second));
272 EXPECT_EQ(expected_value,
273 TimeTicks::FromQPCValue(qpc_value - 1));
274 }
OLDNEW
« no previous file with comments | « base/time/time_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698