Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/collection/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build/
packages
.packages
pubspec.lock
benchmark/*.exe
65 changes: 65 additions & 0 deletions pkgs/collection/benchmark/deep_collection_equality.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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.

import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:collection/collection.dart';

void main() {
for (var unordered in [true, false]) {
DeepCollectionEqualityEqualsBenchmark(unordered).report();
DeepCollectionEqualityHashBenchmark(unordered).report();
}
}

class DeepCollectionEqualityBase extends BenchmarkBase {
final DeepCollectionEquality equality;

DeepCollectionEqualityBase(bool unordered, String function)
: equality = unordered
? const DeepCollectionEquality.unordered()
: const DeepCollectionEquality(),
super('DeepCollectionQuality${unordered ? 'Unordered' : ''}.$function');
}

class DeepCollectionEqualityHashBenchmark extends DeepCollectionEqualityBase {
DeepCollectionEqualityHashBenchmark(bool unordered)
: super(unordered, 'hash');

@override
void run() {
hash = equality.hash(mapA);
}

static int hash = 0;
}

class DeepCollectionEqualityEqualsBenchmark extends DeepCollectionEqualityBase {
DeepCollectionEqualityEqualsBenchmark(bool unordered)
: super(unordered, 'equals');

@override
void run() {
equals = equality.equals(mapA, mapB);
}

static bool equals = false;
}

final mapA = {
for (var i = 0; i < 100; i++)
{
[
for (var j = i; j < i + 10; j++) j,
]: i.isEven ? i : '$i',
}
};

final mapB = {
for (var i = 0; i < 100; i++)
{
[
for (var j = i; j < i + 10; j++) j,
]: i.isEven ? i : '$i',
}
};
1 change: 1 addition & 0 deletions pkgs/collection/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ environment:
sdk: ^3.4.0

dev_dependencies:
benchmark_harness: ^2.3.1
dart_flutter_team_lints: ^3.0.0
test: ^1.16.6
Loading