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

Unified Diff: packages/observe/benchmark/setup_observation_benchmark_base.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 side-by-side diff with in-line comments
Download patch
Index: packages/observe/benchmark/setup_observation_benchmark_base.dart
diff --git a/packages/observe/benchmark/setup_observation_benchmark_base.dart b/packages/observe/benchmark/setup_observation_benchmark_base.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ef1545c63dab1612d4ceec444efe6b0db407db9e
--- /dev/null
+++ b/packages/observe/benchmark/setup_observation_benchmark_base.dart
@@ -0,0 +1,74 @@
+// Copyright (c) 2013, 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 observe.test.benchmark.setup_observation_benchmark_base;
+
+import 'dart:async';
+import 'dart:html';
+import 'package:observe/observe.dart';
+import 'package:benchmark_harness/benchmark_harness.dart';
+
+abstract class SetupObservationBenchmarkBase extends BenchmarkBase {
+ /// The number of objects to create and observe.
+ final int objectCount;
+
+ /// The current configuration.
+ final String config;
+
+ /// The objects we want to observe.
+ List<Observable> objects;
+
+ SetupObservationBenchmarkBase(String name, this.objectCount, this.config)
+ : super(name);
+
+ /// Subclasses should use this method to return an observable object to be
+ /// benchmarked.
+ Observable newObject();
+
+ /// Subclasses should override this to do anything other than a default change
+ /// listener. It must return either a StreamSubscription or a PathObserver.
+ newObserver(obj) => obj.changes.listen((_) {});
+
+ /// Set up each benchmark by creating all the objects.
+ @override
+ void setup() {
+ objects = [];
+ while (objects.length < objectCount) {
+ objects.add(newObject());
+ }
+ }
+
+ /// Tear down each the benchmark and remove all listeners.
+ @override
+ void teardown() {
+ while (objects.isNotEmpty) {
+ var obj = objects.removeLast();
+ if (obj.hasObservers || (obj is ObservableList && obj.hasListObservers)) {
+ window.alert('Observers leaked!');
+ }
+ }
+ objects = null;
+ }
+
+ /// Run the benchmark by creating a listener on each object.
+ @override
+ void run() {
+ for (var object in objects) {
+ var observer = newObserver(object);
+
+ // **Note:** This is different than the JS implementation. Since run can
+ // be called an arbitrary number of times between [setup] and [teardown],
+ // we clean up all observers as we go. This means we are measuring both
+ // the setup and teardown of observers, versus the setup only in the
+ // JS benchmark. Not cleaning these up ends up giving `oh snap` errors.
+ if (observer is StreamSubscription) {
+ observer.cancel();
+ } else if (observer is PathObserver) {
+ observer.close();
+ } else {
+ throw 'Unknown observer type ${observer.runtimeType}. Only '
+ '[PathObserver] and [StreamSubscription] are supported.';
+ }
+ }
+ }
+}
« no previous file with comments | « packages/observe/benchmark/setup_observable_list_benchmark.dart ('k') | packages/observe/benchmark/setup_path_benchmark.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698