-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a basic benchmark for DeepCollectionEquality (#717)
I wanted to check the performance impact of using `.entries` instead of `.keys` followed by a lookup, so I wrote this. Will send out that PR separately - spoiler alert we might not want to land it 🤣 .
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ build/ | |
packages | ||
.packages | ||
pubspec.lock | ||
benchmark/*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters