Chromium Code Reviews| Index: pkg/polymer_expressions/benchmark/eval.dart |
| diff --git a/pkg/polymer_expressions/benchmark/eval.dart b/pkg/polymer_expressions/benchmark/eval.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aad2cfbc2a719e331f88f02a7a8f66a434fe40b3 |
| --- /dev/null |
| +++ b/pkg/polymer_expressions/benchmark/eval.dart |
| @@ -0,0 +1,41 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library polymer_expressions.benchmark.eval; |
| + |
| +import 'package:benchmark_harness/benchmark_harness.dart'; |
| +import 'package:polymer_expressions/parser.dart' show parse; |
| +import 'package:polymer_expressions/eval.dart' show eval, Scope; |
| + |
| +class Foo { |
| + final Bar bar; |
| + Foo(this.bar); |
| +} |
| + |
| +class Bar { |
| + String baz; |
| + Bar(this.baz); |
| +} |
| + |
| +/** |
| + * Measures eval time of several expressions. Parsing time is not included. |
| + */ |
| +class PolymerEvalBenchmark extends BenchmarkBase { |
| + PolymerEvalBenchmark() : super('PolymerEvalBenchmark'); |
| + |
| + final expr = parse('foo.bar.baz'); |
|
Jennifer Messerly
2013/11/15 22:32:58
just a rough sense based on what I've seen in code
|
| + final expr2 = parse('(1 + 2) * 3'); |
| + final scope = new Scope(variables: {'foo': new Foo(new Bar('hello'))}); |
| + |
| + run() { |
| + var value = eval(expr, scope); |
| + if (value != 'hello') throw new StateError(value); |
| + value = eval(expr2, scope); |
| + if (value != 9) throw new StateError(value); |
| + } |
| +} |
| + |
| +main() { |
| + new PolymerEvalBenchmark().report(); |
| +} |