Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A simple stopwatch interface to measure elapsed time. | 8 * A simple stopwatch interface to measure elapsed time. |
| 9 */ | 9 */ |
| 10 class Stopwatch { | 10 class Stopwatch { |
| 11 /** | 11 /** |
| 12 * Frequency of the elapsed counter in Hz. | 12 * Frequency of the elapsed counter in Hz. |
| 13 */ | 13 */ |
| 14 final int frequency = _frequency(); | 14 int get frequency => _frequency; |
|
Lasse Reichstein Nielsen
2014/06/20 23:29:52
Perhaps make this one external, so you don't need
floitsch
2014/06/23 08:54:26
_frequency is a static field.
| |
| 15 | 15 |
| 16 // The _start and _stop fields capture the time when [start] and [stop] | 16 // The _start and _stop fields capture the time when [start] and [stop] |
| 17 // are called respectively. | 17 // are called respectively. |
| 18 // If _start is null, then the [Stopwatch] has not been started yet. | 18 // If _start is null, then the [Stopwatch] has not been started yet. |
| 19 // If _stop is null, then the [Stopwatch] has not been stopped yet, | 19 // If _stop is null, then the [Stopwatch] has not been stopped yet, |
| 20 // or is running. | 20 // or is running. |
| 21 int _start; | 21 int _start; |
| 22 int _stop; | 22 int _stop; |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Creates a [Stopwatch] in stopped state with a zero elapsed count. | 25 * Creates a [Stopwatch] in stopped state with a zero elapsed count. |
| 26 * | 26 * |
| 27 * The following example shows how to start a [Stopwatch] | 27 * The following example shows how to start a [Stopwatch] |
| 28 * immediately after allocation. | 28 * immediately after allocation. |
| 29 * | 29 * |
| 30 * Stopwatch stopwatch = new Stopwatch()..start(); | 30 * Stopwatch stopwatch = new Stopwatch()..start(); |
| 31 */ | 31 */ |
| 32 Stopwatch(); | 32 Stopwatch() { |
| 33 _initTicker(); | |
| 34 } | |
| 33 | 35 |
| 34 /** | 36 /** |
| 35 * Starts the [Stopwatch]. | 37 * Starts the [Stopwatch]. |
| 36 * | 38 * |
| 37 * The [elapsed] count is increasing monotonically. If the [Stopwatch] has | 39 * The [elapsed] count is increasing monotonically. If the [Stopwatch] has |
| 38 * been stopped, then calling start again restarts it without resetting the | 40 * been stopped, then calling start again restarts it without resetting the |
| 39 * [elapsed] count. | 41 * [elapsed] count. |
| 40 * | 42 * |
| 41 * If the [Stopwatch] is currently running, then calling start does nothing. | 43 * If the [Stopwatch] is currently running, then calling start does nothing. |
| 42 */ | 44 */ |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 int get elapsedMilliseconds { | 122 int get elapsedMilliseconds { |
| 121 return (elapsedTicks * 1000) ~/ frequency; | 123 return (elapsedTicks * 1000) ~/ frequency; |
| 122 } | 124 } |
| 123 | 125 |
| 124 | 126 |
| 125 /** | 127 /** |
| 126 * Returns wether the [StopWatch] is currently running. | 128 * Returns wether the [StopWatch] is currently running. |
| 127 */ | 129 */ |
| 128 bool get isRunning => _start != null && _stop == null; | 130 bool get isRunning => _start != null && _stop == null; |
| 129 | 131 |
| 130 external static int _frequency(); | 132 /** |
| 133 * Cached frequency of the system. Must be initialized in [_initTicker]; | |
| 134 */ | |
| 135 static int _frequency; | |
| 136 | |
| 137 /** | |
| 138 * Initializes the time-measuring system. *Must* initialize the [_frequency] | |
| 139 * variable. | |
| 140 */ | |
| 141 external static void _initTicker(); | |
| 131 external static int _now(); | 142 external static int _now(); |
| 132 } | 143 } |
| OLD | NEW |