Add system list polymorphism cases in Iterators benchmark

Change-Id: Iee3d126370d314609cd25c8ac015fc360c9ae16f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232202
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This commit is contained in:
Stephen Adams 2022-02-10 18:38:41 +00:00 committed by Commit Bot
parent 8652944f72
commit bb2d193aaf
2 changed files with 94 additions and 100 deletions

View file

@ -331,6 +331,60 @@ class BenchmarkListIntGrowable extends MonoBenchmark {
}
}
class BenchmarkListIntSystem1 extends MonoBenchmark {
// The List type here is not quite monomorphic. It is the choice between two
// 'system' Lists: a const List and a growable List. It is quite common to
// have growable and const lists at the same use-site (e.g. the const coming
// from a default argument).
//
// Ideally some combination of the class heirarchy or compiler tricks would
// ensure there is little cost of having this gentle polymorphism.
BenchmarkListIntSystem1(int size)
: _list1 = List.generate(size, (i) => i),
_list2 = generateConstListOfInt(size),
super('List.int.growable.and.const', size);
final List<int> _list1;
final List<int> _list2;
bool _flip = false;
@override
void sinkMono() {
_flip = !_flip;
final list = _flip ? _list1 : _list2;
for (final value in list) {
sink = value;
}
}
}
class BenchmarkListIntSystem2 extends MonoBenchmark {
// The List type here is not quite monomorphic. It is the choice between two
// 'system' Lists: a const List and a fixed-length List. It is quite common to
// have fixed-length and const lists at the same use-site (e.g. the const
// coming from a default argument).
//
// Ideally some combination of the class heirarchy or compiler tricks would
// ensure there is little cost of having this gentle polymorphism.
BenchmarkListIntSystem2(int size)
: _list1 = List.generate(size, (i) => i, growable: false),
_list2 = generateConstListOfInt(size),
super('List.int.fixed.and.const', size);
final List<int> _list1;
final List<int> _list2;
bool _flip = false;
@override
void sinkMono() {
_flip = !_flip;
final list = _flip ? _list1 : _list2;
for (final value in list) {
sink = value;
}
}
}
/// A simple Iterable that yields the integers 0 through `length`.
///
/// This Iterable serves as the minimal interesting example to serve as a
@ -492,6 +546,8 @@ void main(List<String> commandLineArguments) {
Benchmark('Runes', size, (n) => generateString(n).runes),
// ---
BenchmarkListIntGrowable(size),
BenchmarkListIntSystem1(size),
BenchmarkListIntSystem2(size),
Benchmark('List.int.growable', size,
(n) => List<int>.of(UpTo(n), growable: true)),
Benchmark('List.int.fixed', size,

View file

@ -12,6 +12,11 @@ Set<int> generateConstSetOfInt(int n) {
(throw ArgumentError.value(n, 'n', 'size not supported'));
}
List<int> generateConstListOfInt(int n) {
return constListOfIntTable[n] ??
(throw ArgumentError.value(n, 'n', 'size not supported'));
}
const Map<int, Map<int, int>> constMapIntIntTable = {
0: constMapIntInt0,
1: constMapIntInt1,
@ -136,104 +141,37 @@ const Set<int> constSetOfInt0 = {};
const Set<int> constSetOfInt1 = {0};
const Set<int> constSetOfInt2 = {0, 1};
const Set<int> constSetOfInt100 = {
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99
...{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
...{10, 11, 12, 13, 14, 15, 16, 17, 18, 19},
...{20, 21, 22, 23, 24, 25, 26, 27, 28, 29},
...{30, 31, 32, 33, 34, 35, 36, 37, 38, 39},
...{40, 41, 42, 43, 44, 45, 46, 47, 48, 49},
...{50, 51, 52, 53, 54, 55, 56, 57, 58, 59},
...{60, 61, 62, 63, 64, 65, 66, 67, 68, 69},
...{70, 71, 72, 73, 74, 75, 76, 77, 78, 79},
...{80, 81, 82, 83, 84, 85, 86, 87, 88, 89},
...{90, 91, 92, 93, 94, 95, 96, 97, 98, 99}
};
const Map<int, List<int>> constListOfIntTable = {
0: constListOfInt0,
1: constListOfInt1,
2: constListOfInt2,
100: constListOfInt100
};
const List<int> constListOfInt0 = [];
const List<int> constListOfInt1 = [0];
const List<int> constListOfInt2 = [0, 1];
const List<int> constListOfInt100 = [
...[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
...[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
...[20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
...[30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
...[40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
...[50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
...[60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
...[70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
...[80, 81, 82, 83, 84, 85, 86, 87, 88, 89],
...[90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
];