OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * A simple implementation of the [Stopwatch] interface. | 6 * A simple implementation of the [Stopwatch] interface. |
7 */ | 7 */ |
8 class StopwatchImplementation implements Stopwatch { | 8 class StopwatchImplementation implements Stopwatch { |
9 // The _start and _stop fields capture the time when [start] and [stop] | 9 // The _start and _stop fields capture the time when [start] and [stop] |
10 // are called respectively. | 10 // are called respectively. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // If [_start] is not null, then the stopwatch had already been started. It | 43 // If [_start] is not null, then the stopwatch had already been started. It |
44 // may running right now. | 44 // may running right now. |
45 _start = _now(); | 45 _start = _now(); |
46 if (_stop !== null) { | 46 if (_stop !== null) { |
47 // The watch is not running. So simply set the [_stop] to [_start] thus | 47 // The watch is not running. So simply set the [_stop] to [_start] thus |
48 // having an elapsed time of 0. | 48 // having an elapsed time of 0. |
49 _stop = _start; | 49 _stop = _start; |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 int elapsed() { | 53 int get elapsedTicks { |
54 if (_start === null) { | 54 if (_start === null) { |
55 return 0; | 55 return 0; |
56 } | 56 } |
57 return (_stop === null) ? (_now() - _start) : (_stop - _start); | 57 return (_stop === null) ? (_now() - _start) : (_stop - _start); |
58 } | 58 } |
59 | 59 |
60 int elapsedInUs() { | 60 int get elapsedMicroseconds { |
61 return (elapsed() * 1000000) ~/ frequency(); | 61 return (elapsedTicks * 1000000) ~/ frequency; |
62 } | 62 } |
63 | 63 |
64 int elapsedInMs() { | 64 int get elapsedMilliseconds { |
65 return (elapsed() * 1000) ~/ frequency(); | 65 return (elapsedTicks * 1000) ~/ frequency; |
66 } | 66 } |
67 | 67 |
68 int frequency() => _frequency(); | 68 int get frequency => _frequency(); |
69 | 69 |
70 external static int _frequency(); | 70 external static int _frequency(); |
71 external static int _now(); | 71 external static int _now(); |
72 } | 72 } |
OLD | NEW |