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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/path/benchmark/benchmark.dart
diff --git a/pkg/path/benchmark/benchmark.dart b/pkg/path/benchmark/benchmark.dart
new file mode 100644
index 0000000000000000000000000000000000000000..60a2b5318adcf36c500004133fafb208bd471c5f
--- /dev/null
+++ b/pkg/path/benchmark/benchmark.dart
@@ -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',
+ ],
+};
« 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