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

Side by Side Diff: packages/path/benchmark/benchmark.dart

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years 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 | « packages/path/CHANGELOG.md ('k') | packages/path/lib/path.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4
5 import '../lib/path.dart' as path; 5 import '../lib/path.dart' as path;
6 6
7 void runBenchmark(String name, Function func, List files) { 7 void runBenchmark(String name, Function func, List files) {
8 // Warmup. 8 // Warmup.
9 for (int i = 0; i < 10000; i++) { 9 for (int i = 0; i < 10000; i++) {
10 for (var p in files) { 10 for (var p in files) {
11 func(p); 11 func(p);
12 } 12 }
13 } 13 }
14 var count = 100000; 14 var count = 100000;
15 var sw = new Stopwatch()..start(); 15 var sw = new Stopwatch()..start();
16 for (int i = 0; i < count; i++) { 16 for (int i = 0; i < count; i++) {
17 for (var p in files) { 17 for (var p in files) {
18 func(p); 18 func(p);
19 } 19 }
20 } 20 }
21 print("$name: ${count / sw.elapsedMicroseconds} iter/us (${sw.elapsed})"); 21 print("$name: ${count / sw.elapsedMicroseconds} iter/us (${sw.elapsed})");
22 } 22 }
23 23
24 void runBenchmarkTwoArgs(String name, Function func, List files) {
25 // Warmup.
26 for (int i = 0; i < 1000; i++) {
27 for (var file1 in files) {
28 for (var file2 in files) {
29 func(file1, file2);
30 }
31 }
32 }
33
34 var count = 10000;
35 var sw = new Stopwatch()..start();
36 for (int i = 0; i < count; i++) {
37 for (var file1 in files) {
38 for (var file2 in files) {
39 func(file1, file2);
40 }
41 }
42 }
43 print("$name: ${count / sw.elapsedMicroseconds} iter/us (${sw.elapsed})");
44 }
45
24 main(args) { 46 main(args) {
25 for (var style in [path.Style.posix, path.Style.url, path.Style.windows]) { 47 for (var style in [path.Style.posix, path.Style.url, path.Style.windows]) {
26 var context = new path.Context(style: style); 48 var context = new path.Context(style: style);
27 var files = COMMON_PATHS.toList()..addAll(STYLE_PATHS[style]); 49 var files = COMMON_PATHS.toList()..addAll(STYLE_PATHS[style]);
28 50
29 void benchmark(name, func) { 51 benchmark(name, func) {
30 name = style.name + '-' + name; 52 name = style.name + '-' + name;
31 if (args.isEmpty || args.any((arg) => name.contains(arg))) { 53 if (args.isEmpty || args.any((arg) => name.contains(arg))) {
32 runBenchmark(name, func, files); 54 runBenchmark(name, func, files);
33 } 55 }
34 } 56 }
35 57
58 benchmarkTwoArgs(name, func) {
59 name = style.name + '-' + name + '-two';
60 if (args.isEmpty || args.any((arg) => name.contains(arg))) {
61 runBenchmarkTwoArgs(name, func, files);
62 }
63 }
64
65 benchmark('absolute', context.absolute);
36 benchmark('basename', context.basename); 66 benchmark('basename', context.basename);
37 benchmark('basenameWithoutExtension', context.basenameWithoutExtension); 67 benchmark('basenameWithoutExtension', context.basenameWithoutExtension);
38 benchmark('dirname', context.dirname); 68 benchmark('dirname', context.dirname);
39 benchmark('extension', context.extension); 69 benchmark('extension', context.extension);
40 benchmark('rootPrefix', context.rootPrefix); 70 benchmark('rootPrefix', context.rootPrefix);
41 benchmark('isAbsolute', context.isAbsolute); 71 benchmark('isAbsolute', context.isAbsolute);
42 benchmark('isRelative', context.isRelative); 72 benchmark('isRelative', context.isRelative);
43 benchmark('isRootRelative', context.isRootRelative); 73 benchmark('isRootRelative', context.isRootRelative);
44 benchmark('normalize', context.normalize); 74 benchmark('normalize', context.normalize);
45 benchmark('relative', context.relative); 75 benchmark('relative', context.relative);
76 benchmarkTwoArgs('relative', context.relative);
46 benchmark('toUri', context.toUri); 77 benchmark('toUri', context.toUri);
47 benchmark('prettyUri', context.prettyUri); 78 benchmark('prettyUri', context.prettyUri);
79 benchmarkTwoArgs('isWithin', context.isWithin);
80 }
81
82 if (args.isEmpty || args.any((arg) => arg == 'current')) {
83 runBenchmark('current', (_) => path.current, [null]);
48 } 84 }
49 } 85 }
50 86
51 const COMMON_PATHS = const ['.', '..', 'out/ReleaseIA32/packages']; 87 const COMMON_PATHS = const ['.', '..', 'out/ReleaseIA32/packages'];
52 88
53 final STYLE_PATHS = { 89 final STYLE_PATHS = {
54 path.Style.posix: [ 90 path.Style.posix: [
55 '/home/user/dart/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart', 91 '/home/user/dart/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart',
56 ], 92 ],
57 path.Style.url: [ 93 path.Style.url: [
58 'https://example.server.org/443643002/path?top=yes#fragment', 94 'https://example.server.org/443643002/path?top=yes#fragment',
59 ], 95 ],
60 path.Style.windows: [ 96 path.Style.windows: [
61 r'C:\User\me\', 97 r'C:\User\me\',
62 r'\\server\share\my\folders\some\file.data', 98 r'\\server\share\my\folders\some\file.data',
63 ], 99 ],
64 }; 100 };
OLDNEW
« no previous file with comments | « packages/path/CHANGELOG.md ('k') | packages/path/lib/path.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698