| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library fasta.ticker; |
| 6 |
| 7 class Ticker { |
| 8 final Stopwatch sw = new Stopwatch()..start(); |
| 9 |
| 10 bool isVerbose; |
| 11 |
| 12 Duration previousTick; |
| 13 |
| 14 Ticker({this.isVerbose: true}) { |
| 15 previousTick = sw.elapsed; |
| 16 } |
| 17 |
| 18 void logMs(Object message) { |
| 19 log((Duration elapsed, Duration sinceStart) { |
| 20 print("$sinceStart: $message in ${elapsed.inMilliseconds}ms."); |
| 21 }); |
| 22 } |
| 23 |
| 24 void log(void f(Duration elapsed, Duration sinceStart)) { |
| 25 Duration elapsed = sw.elapsed; |
| 26 try { |
| 27 if (isVerbose) f(elapsed - previousTick, elapsed); |
| 28 } finally { |
| 29 previousTick = sw.elapsed; |
| 30 } |
| 31 } |
| 32 } |
| OLD | NEW |