From 0874a34741eafc8f39cb4c90bb89b6b6324414bb Mon Sep 17 00:00:00 2001 From: David Morgan Date: Thu, 13 Nov 2025 09:45:13 +0100 Subject: [PATCH 1/2] Add random benchmark shape. --- _benchmark/lib/shape.dart | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/_benchmark/lib/shape.dart b/_benchmark/lib/shape.dart index 621c5fbac6..b3538334f2 100644 --- a/_benchmark/lib/shape.dart +++ b/_benchmark/lib/shape.dart @@ -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. @@ -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 importNames( int libraryNumber, { @@ -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) + 1) + 1, + benchmarkSize: benchmarkSize, + ), + ]; } } } + +final _random = Random(0); From c244ae3744ce7664c33b391bbd9fd252a58149dd Mon Sep 17 00:00:00 2001 From: David Morgan Date: Fri, 14 Nov 2025 09:55:05 +0100 Subject: [PATCH 2/2] Address review comments. --- _benchmark/lib/shape.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_benchmark/lib/shape.dart b/_benchmark/lib/shape.dart index b3538334f2..1637819206 100644 --- a/_benchmark/lib/shape.dart +++ b/_benchmark/lib/shape.dart @@ -73,7 +73,7 @@ enum Shape { if (_random.nextInt(libraryNumber + 1) == 0) 'app.dart', for (var i = 0; i != numberOfImports; ++i) Benchmarks.libraryName( - _random.nextInt(_random.nextInt(benchmarkSize + 1) + 1) + 1, + _random.nextInt(_random.nextInt(benchmarkSize) + 1), benchmarkSize: benchmarkSize, ), ];