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

Unified Diff: sdk/lib/_internal/lib/js_helper.dart

Issue 345873003: Update timer and adjust frequency. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cache stopwatch work. Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/lib/js_helper.dart
diff --git a/sdk/lib/_internal/lib/js_helper.dart b/sdk/lib/_internal/lib/js_helper.dart
index 8f87ac4f8cbdcc4871f860ed5a5ff805f8c31cf1..6611363351d15a17d43d3e87bfa6dd1a0ac5cf0e 100644
--- a/sdk/lib/_internal/lib/js_helper.dart
+++ b/sdk/lib/_internal/lib/js_helper.dart
@@ -695,16 +695,23 @@ class Primitives {
static num dateNow() => JS('num', r'Date.now()');
- static num numMicroseconds() {
- if (JS('bool', 'typeof window != "undefined" && window !== null')) {
- var performance = JS('var', 'window.performance');
- if (performance != null &&
- JS('bool', 'typeof #.webkitNow == "function"', performance)) {
- return (1000 * JS('num', '#.webkitNow()', performance)).floor();
- }
- }
- return 1000 * dateNow();
- }
+ static void initTicker() {
+ if (timerFrequency != null) return;
+ // Start with low-resolution. We overwrite the fields if we find better.
+ timerFrequency = 1000;
+ timerTicks = dateNow;
+ if (JS('bool', 'typeof window == "undefined"')) return;
+ var window = JS('var', 'window');
+ if (window == null) return;
+ var performance = JS('var', '#.performance', window);
+ if (performance == null) return;
+ if (JS('bool', 'typeof #.now != "function"', performance)) return;
+ timerFrequency = 1000000;
+ timerTicks = () => (1000 * JS('num', '#.now()', performance)).floor();
+ }
+
+ static int timerFrequency;
+ static Function timerTicks;
static bool get isD8 {
return JS('bool',

Powered by Google App Engine
This is Rietveld 408576698