Skip to content

Commit 928d015

Browse files
committed
[benchmark] DataBenchmarks Legacy Factor
Adjusted the multipliers to run in under 1000 μs. The inner loop multipliers are divided by the `legacyFactor` to achieve the same reported runtime, but in a shorter time and with better precision (less accumulated error).
1 parent 6af0eab commit 928d015

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

benchmark/single-source/DataBenchmarks.swift

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,28 @@ let S = 200 /// String conversions
2222

2323
public let DataBenchmarks = [
2424
BenchmarkInfo(name: "DataCreateEmpty",
25-
runFunction: { for _ in 0..<$0*I { blackHole(Data()) } }, tags: d),
25+
runFunction: { for _ in 0..<$0*I/10 { blackHole(Data()) } },
26+
tags: d, legacyFactor: 10),
2627
BenchmarkInfo(name: "DataCreateSmall",
27-
runFunction: { for _ in 0..<$0*I { blackHole(sampleData(.small)) } },
28-
tags: d),
28+
runFunction: { for _ in 0..<$0*I/1000 { blackHole(sampleData(.small)) } },
29+
tags: d, legacyFactor: 1000),
2930
BenchmarkInfo(name: "DataCreateMedium",
30-
runFunction: { for _ in 0..<$0*M { blackHole(sampleData(.medium)) } },
31-
tags: d),
31+
runFunction: { for _ in 0..<$0*M/100 { blackHole(sampleData(.medium)) } },
32+
tags: d, legacyFactor: 100),
3233

3334
BenchmarkInfo(name: "DataCreateEmptyArray",
34-
runFunction: { for _ in 0..<$0*I { blackHole(Data([])) } }, tags: d),
35+
runFunction: { for _ in 0..<$0*I/50 { blackHole(Data([])) } }, tags: d,
36+
legacyFactor: 50),
3537
BenchmarkInfo(name: "DataCreateSmallArray",
36-
runFunction: { for _ in 0..<$0*I { blackHole(Data(
37-
[0, 1, 2, 3, 4, 5, 6])) } }, tags: d),
38+
runFunction: { for _ in 0..<$0*I/50 { blackHole(Data(
39+
[0, 1, 2, 3, 4, 5, 6])) } }, tags: d, legacyFactor: 50),
3840
BenchmarkInfo(name: "DataCreateMediumArray",
39-
runFunction: { for _ in 0..<$0*M { blackHole(Data([
41+
runFunction: { for _ in 0..<$0*M/20 { blackHole(Data([
4042
0, 1, 2, 3, 4, 5, 6,
4143
0, 1, 2, 3, 4, 5, 6,
4244
0, 1, 2, 3, 4, 5, 6,
4345
0, 1, 2, 3, 4, 5, 6,
44-
])) } }, tags: d),
46+
])) } }, tags: d, legacyFactor: 20),
4547

4648
BenchmarkInfo(name: "DataSubscriptSmall",
4749
runFunction: { for _ in 0..<$0*M { blackHole(small[1]) } }, tags: d),
@@ -56,72 +58,90 @@ public let DataBenchmarks = [
5658
BenchmarkInfo(name: "DataSetCountSmall",
5759
runFunction: { setCount($0*M, data: small, extra: 3) }, tags: d),
5860
BenchmarkInfo(name: "DataSetCountMedium",
59-
runFunction: { setCount($0*M, data: medium, extra: 100) }, tags: d),
61+
runFunction: { setCount($0*M/10, data: medium, extra: 100) }, tags: d,
62+
legacyFactor: 10),
6063

6164
BenchmarkInfo(name: "DataAccessBytesSmall",
6265
runFunction: { withUnsafeBytes($0*M, data: small) }, tags: d),
6366
BenchmarkInfo(name: "DataAccessBytesMedium",
6467
runFunction: { withUnsafeBytes($0*M, data: medium) }, tags: d),
6568

6669
BenchmarkInfo(name: "DataMutateBytesSmall",
67-
runFunction: { withUnsafeMutableBytes($0*M, data: small) }, tags: d),
70+
runFunction: { withUnsafeMutableBytes($0*M/20, data: small) }, tags: d,
71+
legacyFactor: 20),
6872
BenchmarkInfo(name: "DataMutateBytesMedium",
69-
runFunction: { withUnsafeMutableBytes($0*M, data: medium) }, tags: d),
73+
runFunction: { withUnsafeMutableBytes($0*M/20, data: medium) }, tags: d,
74+
legacyFactor: 20),
7075

7176
BenchmarkInfo(name: "DataCopyBytesSmall",
7277
runFunction: { copyBytes($0*M, data: small) }, tags: d),
7378
BenchmarkInfo(name: "DataCopyBytesMedium",
74-
runFunction: { copyBytes($0*M, data: medium) }, tags: d),
79+
runFunction: { copyBytes($0*M/2, data: medium) }, tags: d,
80+
legacyFactor: 2),
7581

7682
BenchmarkInfo(name: "DataAppendBytesSmall",
7783
runFunction: { append($0*M, bytes: 3, to: small) }, tags: d),
7884
BenchmarkInfo(name: "DataAppendBytesMedium",
79-
runFunction: { append($0*M, bytes: 809, to: medium) }, tags: d),
85+
runFunction: { append($0*M/20, bytes: 809, to: medium) }, tags: d,
86+
legacyFactor: 20),
8087

8188
BenchmarkInfo(name: "DataAppendArray",
82-
runFunction: { append($0*M, arraySize: 809, to: medium) }, tags: d),
89+
runFunction: { append($0*M/100, arraySize: 809, to: medium) }, tags: d,
90+
legacyFactor: 100),
8391

8492
BenchmarkInfo(name: "DataReset",
85-
runFunction: { resetBytes($0*M, in: 431..<809, data: medium) }, tags: d),
93+
runFunction: { resetBytes($0*M/100, in: 431..<809, data: medium) },
94+
tags: d, legacyFactor: 100),
8695

8796
BenchmarkInfo(name: "DataReplaceSmall", runFunction: {
88-
replace($0*M, data: medium, subrange:431..<809, with: small) }, tags: d),
97+
replace($0*M/100, data: medium, subrange:431..<809, with: small) },
98+
tags: d, legacyFactor: 100),
8999
BenchmarkInfo(name: "DataReplaceMedium", runFunction: {
90-
replace($0*M, data: medium, subrange:431..<809, with: medium) }, tags: d),
100+
replace($0*M/100, data: medium, subrange:431..<809, with: medium) },
101+
tags: d, legacyFactor: 100),
91102
BenchmarkInfo(name: "DataReplaceLarge", runFunction: {
92-
replace($0*M, data: medium, subrange:431..<809, with: large) }, tags: d),
103+
replace($0*M/100, data: medium, subrange:431..<809, with: large) },
104+
tags: d, legacyFactor: 100),
93105

94106
BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: {
95-
replaceBuffer($0*M, data: medium, subrange:431..<809, with: small) },
96-
tags: d),
107+
replaceBuffer($0*M/100, data: medium, subrange:431..<809, with: small) },
108+
tags: d, legacyFactor: 100),
97109
BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: {
98-
replaceBuffer($0*M, data: medium, subrange:431..<809, with: medium) },
99-
tags: d),
110+
replaceBuffer($0*M/100, data: medium, subrange:431..<809, with: medium) },
111+
tags: d, legacyFactor: 100),
100112
BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: {
101-
replaceBuffer($0*M, data: medium, subrange:431..<809, with: large) },
113+
replaceBuffer($0*10, data: medium, subrange:431..<809, with: large) },
102114
tags: d),
103115

104116
BenchmarkInfo(name: "DataAppendSequence",
105-
runFunction: { append($0*M, sequenceLength: 809, to: medium) }, tags: d),
117+
runFunction: { append($0*M/100, sequenceLength: 809, to: medium) },
118+
tags: d, legacyFactor: 100),
106119

107120
BenchmarkInfo(name: "DataAppendDataSmallToSmall",
108-
runFunction: { append($0*M, data: small, to: small) }, tags: d),
121+
runFunction: { append($0*M/20, data: small, to: small) }, tags: d,
122+
legacyFactor: 20),
109123
BenchmarkInfo(name: "DataAppendDataSmallToMedium",
110-
runFunction: { append($0*M, data: small, to: medium) }, tags: d),
124+
runFunction: { append($0*M/20, data: small, to: medium) }, tags: d,
125+
legacyFactor: 20),
111126
BenchmarkInfo(name: "DataAppendDataSmallToLarge",
112-
runFunction: { append($0*M, data: small, to: large) }, tags: d),
127+
runFunction: { append($0*M/200, data: small, to: large) }, tags: d,
128+
legacyFactor: 200),
113129
BenchmarkInfo(name: "DataAppendDataMediumToSmall",
114-
runFunction: { append($0*M, data: medium, to: small) }, tags: d),
130+
runFunction: { append($0*M/20, data: medium, to: small) }, tags: d,
131+
legacyFactor: 20),
115132
BenchmarkInfo(name: "DataAppendDataMediumToMedium",
116-
runFunction: { append($0*M, data: medium, to: medium) }, tags: d),
133+
runFunction: { append($0*M/20, data: medium, to: medium) }, tags: d,
134+
legacyFactor: 20),
117135
BenchmarkInfo(name: "DataAppendDataMediumToLarge",
118-
runFunction: { append($0*M, data: medium, to: large) }, tags: d),
136+
runFunction: { append($0*50, data: medium, to: large) }, tags: d),
119137
BenchmarkInfo(name: "DataAppendDataLargeToSmall",
120-
runFunction: { append($0*M, data: large, to: small) }, tags: d),
138+
runFunction: { append($0*M/200, data: large, to: small) }, tags: d,
139+
legacyFactor: 200),
121140
BenchmarkInfo(name: "DataAppendDataLargeToMedium",
122-
runFunction: { append($0*M, data: large, to: medium) }, tags: d),
141+
runFunction: { append($0*M/200, data: large, to: medium) }, tags: d,
142+
legacyFactor: 200),
123143
BenchmarkInfo(name: "DataAppendDataLargeToLarge",
124-
runFunction: { append($0*M, data: large, to: large) }, tags: d),
144+
runFunction: { append($0*50, data: large, to: large) }, tags: d),
125145

126146
BenchmarkInfo(name: "DataToStringEmpty",
127147
runFunction: { string($0*S, from: emptyData) }, tags: d, legacyFactor: 50),

0 commit comments

Comments
 (0)