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

Unified Diff: pkg/path/test/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/test/benchmark.dart
diff --git a/pkg/path/test/benchmark.dart b/pkg/path/test/benchmark.dart
new file mode 100644
index 0000000000000000000000000000000000000000..225f2a19c5ad7f19d3b9194f69213a8f521219d5
--- /dev/null
+++ b/pkg/path/test/benchmark.dart
@@ -0,0 +1,77 @@
+// Copyright (c) 2012, 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 'package:unittest/unittest.dart';
+import 'package:path/path.dart' as path;
+
+void benchmark(String name, Function func) {
+ // Warmup.
+ for (int i = 0; i < 10000; i++) {
+ for (var p in PATHS) {
+ func(p);
+ }
+ }
+ var count = 100000;
+ var sw = new Stopwatch()..start();
+ for (int i = 0; i < count; i++) {
+ for (var p in PATHS) {
+ func(p);
+ }
+ }
+ print("$name: ${count / sw.elapsedMicroseconds} iter/us (${sw.elapsed})");
+}
+
+main() {
+ for (var style in [path.Style.posix, path.Style.url, path.Style.windows]) {
+ group(style.name, () {
Bob Nystrom 2014/08/05 15:41:58 I'd consider not using unittest here since it does
Anders Johnsen 2014/08/06 07:42:27 Done.
+ var context = new path.Context(style: style);
+ test('basename', () {
+ benchmark('${style.name}-basename', context.basename);
+ });
+ test('basenameWithoutExtension', () {
+ benchmark('${style.name}-basenameWithoutExtension',
+ context.basenameWithoutExtension);
+ });
+ test('dirname', () {
+ benchmark('${style.name}-dirname', context.dirname);
+ });
+ test('extension', () {
+ benchmark('${style.name}-extension', context.extension);
+ });
+ test('rootPrefix', () {
+ benchmark('${style.name}-rootPrefix', context.rootPrefix);
+ });
+ test('isAbsolute', () {
+ benchmark('${style.name}-isAbsolute', context.isAbsolute);
+ });
+ test('isRelative', () {
+ benchmark('${style.name}-isRelative', context.isRelative);
+ });
+ test('isRootRelative', () {
+ benchmark('${style.name}-isRootRelative', context.isRootRelative);
+ });
+ test('normalize', () {
+ benchmark('${style.name}-normalize', context.normalize);
+ });
+ test('relative', () {
+ benchmark('${style.name}-relative', context.relative);
+ });
+ test('toUri', () {
+ benchmark('${style.name}-toUri', context.toUri);
+ });
+ test('prettyUri', () {
+ benchmark('${style.name}-prettyUri', context.prettyUri);
+ });
+ });
+ }
+}
+
+const PATHS = const [
+ '.',
+ '..',
+ 'out/ReleaseIA32/packages',
+ '/home/user/dart/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart',
+ 'C:\\User\\me\\',
Bob Nystrom 2014/08/05 15:41:58 Nit: use a raw string here and below?
Anders Johnsen 2014/08/06 07:42:27 Done. I think we should continue to add to this l
+ '\\server\\share\\my\\folders\\some\\file.data',
nweiz 2014/08/05 19:40:33 It doesn't seem like we should be running Windows
Anders Johnsen 2014/08/06 07:42:27 Adding some url paths as well. I'd actually prefe
nweiz 2014/08/06 21:08:28 I don't think you should take out the platform-spe
Anders Johnsen 2014/08/07 08:56:10 Done.
+];
« 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