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

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

Issue 443643002: Add benchmark to 'path' package, of the most common methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import '../lib/path.dart' as path;
6
7 void runBenchmark(String name, Function func, List files) {
8 // Warmup.
9 for (int i = 0; i < 10000; i++) {
10 for (var p in files) {
11 func(p);
12 }
13 }
14 var count = 100000;
15 var sw = new Stopwatch()..start();
16 for (int i = 0; i < count; i++) {
17 for (var p in files) {
18 func(p);
19 }
20 }
21 print("$name: ${count / sw.elapsedMicroseconds} iter/us (${sw.elapsed})");
22 }
23
24 main(args) {
25 for (var style in [path.Style.posix, path.Style.url, path.Style.windows]) {
26 var context = new path.Context(style: style);
27 var files = COMMON_PATHS.toList()..addAll(STYLE_PATHS[style]);
28
29 void benchmark(name, func) {
30 name = style.name + '-' + name;
31 if (args.isEmpty || args.any((arg) => name.contains(arg))) {
32 runBenchmark(name, func, files);
33 }
34 }
35
36 benchmark('basename', context.basename);
37 benchmark('basenameWithoutExtension', context.basenameWithoutExtension);
38 benchmark('dirname', context.dirname);
39 benchmark('extension', context.extension);
40 benchmark('rootPrefix', context.rootPrefix);
41 benchmark('isAbsolute', context.isAbsolute);
42 benchmark('isRelative', context.isRelative);
43 benchmark('isRootRelative', context.isRootRelative);
44 benchmark('normalize', context.normalize);
45 benchmark('relative', context.relative);
46 benchmark('toUri', context.toUri);
47 benchmark('prettyUri', context.prettyUri);
48 }
49 }
50
51 const COMMON_PATHS = const [
52 '.',
53 '..',
54 'out/ReleaseIA32/packages',
55 ];
56
57 final STYLE_PATHS = {
58 path.Style.posix: [
59 '/home/user/dart/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart',
60 ],
61 path.Style.url: [
62 'https://example.server.org/443643002/path?top=yes#fragment',
63 ],
64 path.Style.windows: [
65 r'C:\User\me\',
66 r'\\server\share\my\folders\some\file.data',
67 ],
68 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698