Skip to content

Commit b9ae225

Browse files
authored
Add random benchmark shape. (#4280)
* Add random benchmark shape. * Address review comments.
1 parent 8f6a7b5 commit b9ae225

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

_benchmark/lib/shape.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:math';
6+
57
import 'benchmark.dart';
68

79
/// The shape of the dependency graph.
@@ -26,7 +28,10 @@ enum Shape {
2628
///
2729
/// Considered in alphanumeric order, each one has a dependency on the one
2830
/// before. The first library depends on `app.dart`.
29-
backwards;
31+
backwards,
32+
33+
/// Randomly connected libraries.
34+
random;
3035

3136
Iterable<String> importNames(
3237
int libraryNumber, {
@@ -59,6 +64,21 @@ enum Shape {
5964
benchmarkSize: benchmarkSize,
6065
),
6166
];
67+
case Shape.random:
68+
// Use random.nextInt(random.nextInt(...)) to get a distribution of
69+
// imports biased towards lower number libraries, which is more
70+
// realistic than flat random imports.
71+
final numberOfImports = _random.nextInt(_random.nextInt(10) + 1);
72+
return [
73+
if (_random.nextInt(libraryNumber + 1) == 0) 'app.dart',
74+
for (var i = 0; i != numberOfImports; ++i)
75+
Benchmarks.libraryName(
76+
_random.nextInt(_random.nextInt(benchmarkSize) + 1),
77+
benchmarkSize: benchmarkSize,
78+
),
79+
];
6280
}
6381
}
6482
}
83+
84+
final _random = Random(0);

0 commit comments

Comments
 (0)