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

Side by Side Diff: code_transformers/lib/benchmarks.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « code_transformers/lib/assets.dart ('k') | code_transformers/lib/messages/build_logger.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 library code_transformers.benchmarks;
5
6 import 'dart:async';
7 import 'package:barback/barback.dart';
8 import 'src/async_benchmark_base.dart';
9
10 /// A benchmark for testing the performance of transformer phases.
11 class TransformerBenchmark extends AsyncBenchmarkBase {
12 /// Internal abstraction layer for barback.
13 _BenchmarkHelper _helper;
14
15 /// The transformer phases to be ran.
16 final List<List<Transformer>> transformers;
17
18 /// The files to pass to barback.
19 final Map<AssetId, String> files;
20
21 TransformerBenchmark(this.transformers, this.files);
22
23 @override
24 Future setup() {
25 _helper = new _BenchmarkHelper(transformers, files);
26 return new Future.value();
27 }
28
29 @override
30 Future run() => _helper.run();
31
32 @override
33 teardown() {
34 _helper = null;
35 return new Future.value();
36 }
37 }
38
39 /// Barback abstraction layer.
40 class _BenchmarkHelper implements PackageProvider {
41 /// All the files available.
42 final Map<AssetId, String> _files;
43
44 /// All the packages.
45 final Iterable<String> packages;
46
47 /// Internal instance of barback.
48 Barback _barback;
49
50 /// Subscription to barback results.
51 StreamSubscription<BuildResult> resultSubscription;
52
53 _BenchmarkHelper(
54 List<List<Transformer>> transformers, Map<AssetId, String> files)
55 : _files = files,
56 packages = new Set.from(files.keys.map((assetId) => assetId.package)) {
57 _barback = new Barback(this);
58 for (var package in packages) {
59 _barback.updateTransformers(package, transformers);
60 }
61 }
62
63 /// Look up an [AssetId] in [files] and return an [Asset] for it.
64 @override
65 Future<Asset> getAsset(AssetId id) =>
66 new Future.value(new Asset.fromString(id, _files[id]));
67
68 /// Tells barback which files have changed, and thus anything that depends on
69 /// it on should be computed. Returns a [Future] that completes once some
70 /// results are received.
71 Future run([Iterable<AssetId> assetIds]) {
72 if (assetIds == null) assetIds = _files.keys;
73 _barback.updateSources(assetIds);
74 return _barback.results.first;
75 }
76 }
OLDNEW
« no previous file with comments | « code_transformers/lib/assets.dart ('k') | code_transformers/lib/messages/build_logger.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698