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
diff --git a/benchmark/benchmark.dart b/benchmark/benchmark.dart
new file mode 100644
index 0000000..60a2b53
--- /dev/null
+++ b/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',
+  ],
+};