Skip to content
Merged
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
22 changes: 21 additions & 1 deletion _benchmark/lib/shape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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 'dart:math';

import 'benchmark.dart';

/// The shape of the dependency graph.
Expand All @@ -26,7 +28,10 @@ enum Shape {
///
/// Considered in alphanumeric order, each one has a dependency on the one
/// before. The first library depends on `app.dart`.
backwards;
backwards,

/// Randomly connected libraries.
random;

Iterable<String> importNames(
int libraryNumber, {
Expand Down Expand Up @@ -59,6 +64,21 @@ enum Shape {
benchmarkSize: benchmarkSize,
),
];
case Shape.random:
// Use random.nextInt(random.nextInt(...)) to get a distribution of
// imports biased towards lower number libraries, which is more
// realistic than flat random imports.
final numberOfImports = _random.nextInt(_random.nextInt(10) + 1);
return [
if (_random.nextInt(libraryNumber + 1) == 0) 'app.dart',
for (var i = 0; i != numberOfImports; ++i)
Benchmarks.libraryName(
_random.nextInt(_random.nextInt(benchmarkSize) + 1),
benchmarkSize: benchmarkSize,
),
];
}
}
}

final _random = Random(0);