Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Side by Side Diff: pkg/polymer_expressions/benchmark/eval.dart

Issue 74543003: Split out Index AST node from Invoke (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Split out Getter too Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library polymer_expressions.benchmark.eval; 5 library polymer_expressions.benchmark.eval;
6 6
7 import 'package:benchmark_harness/benchmark_harness.dart'; 7 import 'package:benchmark_harness/benchmark_harness.dart';
8 import 'package:polymer_expressions/parser.dart' show parse; 8 import 'package:polymer_expressions/parser.dart' show parse;
9 import 'package:polymer_expressions/eval.dart' show eval, Scope; 9 import 'package:polymer_expressions/eval.dart' show eval, Scope;
10 10
11 class Foo { 11 class Foo {
12 final Bar bar; 12 final Bar bar;
13 Foo(this.bar); 13 Foo(this.bar);
14 } 14 }
15 15
16 class Bar { 16 class Bar {
17 String baz; 17 String baz;
18 Bar(this.baz); 18 Bar(this.baz);
19 } 19 }
20 20
21 /** 21 class EvalBenchmark extends BenchmarkBase {
22 * Measures eval time of several expressions. Parsing time is not included. 22 final expr;
23 */ 23 final scope;
24 class PolymerEvalBenchmark extends BenchmarkBase {
25 PolymerEvalBenchmark() : super('PolymerEvalBenchmark');
26 24
27 final expr = parse('foo.bar.baz'); 25 EvalBenchmark(String name, String expr, {Object model, Map variables})
28 final expr2 = parse('(1 + 2) * 3'); 26 : expr = parse(expr),
29 final scope = new Scope(variables: {'foo': new Foo(new Bar('hello'))}); 27 scope = new Scope(model: model, variables: variables),
28 super('$name: $expr ');
29 }
30 30
31 run() { 31 double total = 0.0;
32 var value = eval(expr, scope); 32
33 if (value != 'hello') throw new StateError(value); 33 benchmark(String name, String expr, {Object model, Map variables}) {
34 value = eval(expr2, scope); 34 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.
35 if (value != 9) throw new StateError(value); 35 print("$name $expr: $score us");
36 } 36 total += score;
37 } 37 }
38 38
39 main() { 39 main() {
40 new PolymerEvalBenchmark().report(); 40
41 benchmark('Constant', '1');
42 benchmark('Top-level Name', 'foo',
43 variables: {'foo': new Foo(new Bar('hello'))});
44 benchmark('Model field', 'bar',
45 model: new Foo(new Bar('hello')));
46 benchmark('Path', 'foo.bar.baz',
47 variables: {'foo': new Foo(new Bar('hello'))});
48 benchmark('Map', 'm["foo"]',
49 variables: {'m': {'foo': 1}});
50 benchmark('Equality', '"abc" == "123"');
51 print('total: $total us');
52
41 } 53 }
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer_expressions/lib/eval.dart » ('j') | pkg/polymer_expressions/lib/eval.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698