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

Unified Diff: lib/benchmarks.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 | « CHANGELOG.md ('k') | lib/src/async_benchmark_base.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/benchmarks.dart
diff --git a/lib/benchmarks.dart b/lib/benchmarks.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c048457134ca82faa3ba9de81137117f51ccc308
--- /dev/null
+++ b/lib/benchmarks.dart
@@ -0,0 +1,76 @@
+// 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.benchmarks;
+
+import 'dart:async';
+import 'package:barback/barback.dart';
+import 'src/async_benchmark_base.dart';
+
+/// A benchmark for testing the performance of transformer phases.
+class TransformerBenchmark extends AsyncBenchmarkBase {
+ /// Internal abstraction layer for barback.
+ _BenchmarkHelper _helper;
+
+ /// The transformer phases to be ran.
+ final List<List<Transformer>> transformers;
+
+ /// The files to pass to barback.
+ final Map<AssetId, String> files;
+
+ TransformerBenchmark(this.transformers, this.files);
+
+ @override
+ Future setup() {
+ _helper = new _BenchmarkHelper(transformers, files);
+ return new Future.value();
+ }
+
+ @override
+ Future run() => _helper.run();
+
+ @override
+ teardown() {
+ _helper = null;
+ return new Future.value();
+ }
+}
+
+/// Barback abstraction layer.
+class _BenchmarkHelper implements PackageProvider {
+ /// All the files available.
+ final Map<AssetId, String> _files;
+
+ /// All the packages.
+ final Iterable<String> packages;
+
+ /// Internal instance of barback.
+ Barback _barback;
+
+ /// Subscription to barback results.
+ StreamSubscription<BuildResult> resultSubscription;
+
+ _BenchmarkHelper(
+ List<List<Transformer>> transformers, Map<AssetId, String> files)
+ : _files = files,
+ packages = new Set.from(files.keys.map((assetId) => assetId.package)) {
+ _barback = new Barback(this);
+ for (var package in packages) {
+ _barback.updateTransformers(package, transformers);
+ }
+ }
+
+ /// Look up an [AssetId] in [files] and return an [Asset] for it.
+ @override
+ Future<Asset> getAsset(AssetId id) =>
+ new Future.value(new Asset.fromString(id, _files[id]));
+
+ /// Tells barback which files have changed, and thus anything that depends on
+ /// it on should be computed. Returns a [Future] that completes once some
+ /// results are received.
+ Future run([Iterable<AssetId> assetIds]) {
+ if (assetIds == null) assetIds = _files.keys;
+ _barback.updateSources(assetIds);
+ return _barback.results.first;
+ }
+}
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/async_benchmark_base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698