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

Unified Diff: test/benchmarks_test.dart

Issue 1080123002: add benchmarks.dart which allows you to easily benchmark transformer code (Closed) Base URL: git@github.com:dart-lang/code-transformers.git@master
Patch Set: code review updates Created 5 years, 8 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 | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/benchmarks_test.dart
diff --git a/test/benchmarks_test.dart b/test/benchmarks_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ca0b31f051614ca1c69bbec1a0a3fa794b0c3397
--- /dev/null
+++ b/test/benchmarks_test.dart
@@ -0,0 +1,42 @@
+// 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.
+library code_transformers.test.benchmarks_test;
+
+import 'package:barback/barback.dart';
+import 'package:code_transformers/benchmarks.dart';
+import 'package:unittest/compact_vm_config.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+ useCompactVMConfiguration();
+
+ test('can benchmark transformers', () {
+ var transformer = new TestTransformer();
+ var transformers = [[transformer]];
+ var id = new AssetId('foo', 'lib/bar.dart');
+ var files = {
+ id: 'library foo.bar;',
+ };
+ var benchmark = new TransformerBenchmark(transformers, files);
+ return benchmark.measure().then((result) {
+ expect(result, greaterThan(0));
+ expect(transformer.filesSeen[id], isNotNull);
+ expect(transformer.filesSeen[id], greaterThanOrEqualTo(10));
+ });
+ });
+}
+
+class TestTransformer extends Transformer {
+ /// Map of the asset ids that were seen to how many times they were seen.
+ Map<AssetId, int> filesSeen = {};
+
+ @override
+ bool isPrimary(AssetId id) => true;
+
+ @override
+ void apply(Transform transform) {
+ filesSeen.putIfAbsent(transform.primaryInput.id, () => 0);
+ filesSeen[transform.primaryInput.id] += 1;
+ }
+}
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698