OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library code_transformers.src.async_benchmark_base; | 4 library code_transformers.src.async_benchmark_base; |
5 | 5 |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 | 7 |
8 /// An adaptation of [BenchmarkBase] from the `benchmark_harness` package that | 8 /// An adaptation of [BenchmarkBase] from the `benchmark_harness` package that |
9 /// works for async benchmarks. | 9 /// works for async benchmarks. |
10 /// TODO(jakemac): Get this merged into `benchmark_harness`. | 10 /// TODO(jakemac): Get this merged into `benchmark_harness`. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if (elapsed > minimumMicros) return new Future.value(false); | 47 if (elapsed > minimumMicros) return new Future.value(false); |
48 return f().then((_) { | 48 return f().then((_) { |
49 elapsed = watch.elapsedMicroseconds; | 49 elapsed = watch.elapsedMicroseconds; |
50 iter++; | 50 iter++; |
51 return true; | 51 return true; |
52 }); | 52 }); |
53 }).then((_) => elapsed / iter); | 53 }).then((_) => elapsed / iter); |
54 } | 54 } |
55 | 55 |
56 // Measures the average time to call `run` once and returns it. | 56 // Measures the average time to call `run` once and returns it. |
57 Future<double> measure({int iterations: 10}) { | 57 Future<double> measure({int iterations: 10}) async { |
58 // Unmeasured setup code. | 58 // Unmeasured setup code. |
59 return setup().then((_) { | 59 await setup(); |
60 // Warmup for at least 100ms. Discard result. | 60 // Warmup for at least 100ms. Discard result. |
61 return measureFor(() => warmup(), 100); | 61 await measureFor(() => warmup(), 100); |
62 }).then((_) { | 62 // Run the benchmark for at least 2000ms. |
63 // Run the benchmark for at least 2000ms. | 63 var result = await measureFor(() => exercise(iterations: iterations), 2000); |
64 return measureFor(() => exercise(iterations: iterations), 2000); | 64 // Tear down the test (unmeasured) and return the result divided by the |
65 }).then((result) { | 65 // number of iterations. |
66 // Tear down the test (unmeasured) and return the result divided by the | 66 await teardown(); |
67 // number of iterations. | 67 return result / iterations; |
68 return teardown().then((_) => result / iterations); | |
69 }); | |
70 } | 68 } |
71 } | 69 } |
OLD | NEW |