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 |
| index aad2cfbc2a719e331f88f02a7a8f66a434fe40b3..5d02d7c032552cf39e9b7fc86dfdbea2632f48d4 100644 |
| --- a/pkg/polymer_expressions/benchmark/eval.dart |
| +++ b/pkg/polymer_expressions/benchmark/eval.dart |
| @@ -18,24 +18,36 @@ class Bar { |
| 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'); |
| - 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); |
| - } |
| +class EvalBenchmark extends BenchmarkBase { |
| + final expr; |
| + final scope; |
| + |
| + EvalBenchmark(String name, String expr, {Object model, Map variables}) |
| + : expr = parse(expr), |
| + scope = new Scope(model: model, variables: variables), |
| + super('$name: $expr '); |
| +} |
| + |
| +double total = 0.0; |
| + |
| +benchmark(String name, String expr, {Object model, Map variables}) { |
| + var score = new EvalBenchmark(name, expr, model: model, variables: variables).measure(); |
|
Jennifer Messerly
2013/11/18 20:28:41
long line
justinfagnani
2013/11/20 03:50:33
Done.
|
| + print("$name $expr: $score us"); |
| + total += score; |
| } |
| main() { |
| - new PolymerEvalBenchmark().report(); |
| + |
| + benchmark('Constant', '1'); |
| + benchmark('Top-level Name', 'foo', |
| + variables: {'foo': new Foo(new Bar('hello'))}); |
| + benchmark('Model field', 'bar', |
| + model: new Foo(new Bar('hello'))); |
| + benchmark('Path', 'foo.bar.baz', |
| + variables: {'foo': new Foo(new Bar('hello'))}); |
| + benchmark('Map', 'm["foo"]', |
| + variables: {'m': {'foo': 1}}); |
| + benchmark('Equality', '"abc" == "123"'); |
| + print('total: $total us'); |
| + |
| } |