-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmark to 'path' package, of the most common methods.
BUG= R=nweiz@google.com, rnystrom@google.com Review URL: https://codereview.chromium.org//443643002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/path@39321 260f80e4-7a28-3924-810f-c04153c831b5
- Loading branch information
ajohnsen@google.com
committed
Aug 18, 2014
1 parent
27dfe34
commit d6f3fb3
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import '../lib/path.dart' as path; | ||
|
||
void runBenchmark(String name, Function func, List files) { | ||
// Warmup. | ||
for (int i = 0; i < 10000; i++) { | ||
for (var p in files) { | ||
func(p); | ||
} | ||
} | ||
var count = 100000; | ||
var sw = new Stopwatch()..start(); | ||
for (int i = 0; i < count; i++) { | ||
for (var p in files) { | ||
func(p); | ||
} | ||
} | ||
print("$name: ${count / sw.elapsedMicroseconds} iter/us (${sw.elapsed})"); | ||
} | ||
|
||
main(args) { | ||
for (var style in [path.Style.posix, path.Style.url, path.Style.windows]) { | ||
var context = new path.Context(style: style); | ||
var files = COMMON_PATHS.toList()..addAll(STYLE_PATHS[style]); | ||
|
||
void benchmark(name, func) { | ||
name = style.name + '-' + name; | ||
if (args.isEmpty || args.any((arg) => name.contains(arg))) { | ||
runBenchmark(name, func, files); | ||
} | ||
} | ||
|
||
benchmark('basename', context.basename); | ||
benchmark('basenameWithoutExtension', context.basenameWithoutExtension); | ||
benchmark('dirname', context.dirname); | ||
benchmark('extension', context.extension); | ||
benchmark('rootPrefix', context.rootPrefix); | ||
benchmark('isAbsolute', context.isAbsolute); | ||
benchmark('isRelative', context.isRelative); | ||
benchmark('isRootRelative', context.isRootRelative); | ||
benchmark('normalize', context.normalize); | ||
benchmark('relative', context.relative); | ||
benchmark('toUri', context.toUri); | ||
benchmark('prettyUri', context.prettyUri); | ||
} | ||
} | ||
|
||
const COMMON_PATHS = const [ | ||
'.', | ||
'..', | ||
'out/ReleaseIA32/packages', | ||
]; | ||
|
||
final STYLE_PATHS = { | ||
path.Style.posix: [ | ||
'/home/user/dart/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart', | ||
], | ||
path.Style.url: [ | ||
'https://example.server.org/443643002/path?top=yes#fragment', | ||
], | ||
path.Style.windows: [ | ||
r'C:\User\me\', | ||
r'\\server\share\my\folders\some\file.data', | ||
], | ||
}; |