OLD | NEW |
(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 ['.', '..', 'out/ReleaseIA32/packages']; |
| 52 |
| 53 final STYLE_PATHS = { |
| 54 path.Style.posix: [ |
| 55 '/home/user/dart/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart', |
| 56 ], |
| 57 path.Style.url: [ |
| 58 'https://example.server.org/443643002/path?top=yes#fragment', |
| 59 ], |
| 60 path.Style.windows: [ |
| 61 r'C:\User\me\', |
| 62 r'\\server\share\my\folders\some\file.data', |
| 63 ], |
| 64 }; |
OLD | NEW |