Skip to content

Commit d62771e

Browse files
authored
perf: Improve comprehensive benchmark to be less finicky (#51)
1 parent 0260c0e commit d62771e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

benchmark/comprehensive_benchmark.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import 'package:benchmark_harness/benchmark_harness.dart';
44
import 'package:ordered_set/comparing.dart';
55
import 'package:ordered_set/ordered_set.dart';
66

7-
const _maxStartingOperations = 1000;
8-
const _maxElement = 1000;
7+
const _maxOperations = 2500;
8+
const _maxElement = 10000;
9+
const _startingSetSize = 500;
910

1011
class ComprehensiveBenchmark extends BenchmarkBase {
1112
final Random r;
@@ -67,18 +68,25 @@ class _Runtime {
6768
}
6869

6970
void iterate() {
70-
while (_totalOperations == 0 || _queue.isNotEmpty) {
71-
if (_totalOperations < _maxStartingOperations) {
72-
for (var i = 0; i < r.nextInt(3) + 2; i++) {
73-
_queueOp(_randomOperation());
74-
}
75-
}
71+
_populateSet();
72+
73+
while (_totalOperations < _maxOperations) {
74+
final operation = _randomOperation();
75+
_queueOp(operation);
76+
}
7677

78+
while (_queue.isNotEmpty) {
7779
final op = _queue.removeAt(0);
7880
op.execute(this, _set).forEach(_queueOp);
7981
}
8082
}
8183

84+
void _populateSet() {
85+
for (var i = 0; i < _startingSetSize; i++) {
86+
_queueOp(_AddOperation(_randomElement()));
87+
}
88+
}
89+
8290
void _queueOp(_Operation op) {
8391
_totalOperations++;
8492
_queue.insert(r.nextInt(_queue.length + 1), op);

0 commit comments

Comments
 (0)