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

Side by Side Diff: test/perf/perf.dart

Issue 11683002: Setting up benchmarks and perf utilities (Closed) Base URL: git@github.com:dart-lang/web-ui.git@master
Patch Set: john comments Created 7 years, 11 months 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
« no previous file with comments | « test/perf/input/todomvc_test.html ('k') | test/perf/update_json.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 /**
6 * This is a helper for perf.sh. We try to run all of the Dart code in one
7 * instance of the Dart VM to reduce warm-up time.
8 */
9 library test.perf.perf;
10
11 import 'dart:io';
12 import 'dart:json';
13 import 'dart:utf' show encodeUtf8;
14 import 'dart:isolate';
15 import 'package:unittest/unittest.dart';
16 import 'package:web_ui/dwc.dart' as dwc;
17
18 import '../compact_vm_config.dart';
19
20 main() {
21 var args = new Options().arguments;
22 var pattern = new RegExp(args.length > 0 ? args[0] : '.');
23
24 useCompactVMConfiguration();
25
26 var lister = new Directory.fromPath(new Path('input')).list();
27 var cwd = new Path(new Directory.current().path);
28 var inputDir = cwd.append('input');
29 var results = {};
30 lister.onFile = (path) {
31 if (!path.endsWith('_test.html') || !pattern.hasMatch(path)) return;
32 var filename = new Path(path).filename;
33 var outDir = cwd.append('output');
34 var htmlPath = outDir.append(filename).toString();
35 var dartPath = outDir.append('${filename}_bootstrap.dart').toString();
36
37 test('drt-compile $filename', () {
38 expect(dwc.run(['-o', 'output/', path], printTime: false)
39 .transform((res) {
40 expect(res.messages.length, 0,
41 reason: Strings.join(res.messages, '\n'));
42 }), completes);
43 });
44
45 test('drt-run $filename', () {
46 results['dart $filename'] = null;
47 var outputPath = '$htmlPath.txt';
48 expect(Process.run('DumpRenderTree', [htmlPath]).transform((res) {
49 results['dart $filename'] = _extractResult(res.stdout);
50 expect(res.exitCode, 0, reason:
51 'DumpRenderTree exited with a non-zero exit code, when running '
52 'on $filename. Contents of stderr: \n${res.stderr}');
53 }), completes);
54 });
55
56 test('dart2js-compile $filename', () {
57 expect(Process.run('dart2js', ["-o$dartPath.js", dartPath]).transform(
58 (res) {
59 if (res.stdout != null && res.stdout != '') print(res.stdout);
60 expect(res.exitCode, 0, reason:
61 'dart2js exited with a non-zero exit code, when running '
62 'on $dartPath. Contents of stderr: \n${res.stderr}');
63 }), completes);
64 });
65
66 test('js-drt-run $filename', () {
67 results['js $filename'] = null;
68 // Create new .html file to ensure DRT runs the code as Javascript.
69 var htmlJSPath = '${htmlPath}_js.html';
70 var html = new File(htmlPath).readAsStringSync()
71 .replaceAll(new RegExp('<script .*/start_dart.js"></script>'), '')
72 .replaceAll(new RegExp('<script .*/dart.js"></script>'), '')
73 .replaceAll('"application/dart"', '"application/javascript"')
74 .replaceAll('.html_bootstrap.dart', '.html_bootstrap.dart.js');
75 new File(htmlJSPath).writeAsStringSync(html);
76
77 expect(Process.run('DumpRenderTree', [htmlJSPath]).transform((res) {
78 results['js $filename'] = _extractResult(res.stdout);
79 expect(res.exitCode, 0, reason:
80 'DumpRenderTree exited with a non-zero exit code, when running '
81 'on $filename. Contents of stderr: \n${res.stderr}');
82 }), completes);
83 });
84
85 lister.onDone = (done) {
86 test('printing-results', () {
87 print('\nRESULTS');
88 results.forEach((k, v) {
89 print(' $k: $v');
90 });
91 expect(_writeFile('$cwd/output/results.json', JSON.stringify(results)),
92 completes);
93 });
94 };
95 };
96 }
97
98 final _SCORE_REGEX = new RegExp(r'^CONSOLE.*benchmark-score: (.*)$',
99 multiLine: true);
100
101 _extractResult(String s) {
102 var match = _SCORE_REGEX.firstMatch(s);
103 return (match != null) ? double.parse(match.group(1)) : null;
104 }
105
106 Future _writeFile(String path, String text) {
107 return new File(path).open(FileMode.WRITE)
108 .chain((file) => file.writeString(text))
109 .chain((file) => file.close());
110 }
OLDNEW
« no previous file with comments | « test/perf/input/todomvc_test.html ('k') | test/perf/update_json.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698