Skip to content

Commit 20f91e7

Browse files
committed
[benchmark] ArrayAppend fine-tune Legacy Factor
Lowered the workload of string appending bechmarks a bit further, to get them under 1ms in `O` and 10ms in `Onone` builds. Fine tuned the legacy factor to match original `O` runtimes — the changes are non-linear because of complications from double loop and amortized array growth costs. These string appending benchmarks along with * ArrayPlusEqualFiveElementCollection and * ArrayPlusEqualSingleElementCollection are likely to show different performance in `Osize` and `Onone` builds because of the non-linearity of their original implementation.
1 parent 150d748 commit 20f91e7

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

benchmark/single-source/ArrayAppend.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public let ArrayAppend = [
1919
BenchmarkInfo(name: "ArrayAppend", runFunction: run_ArrayAppend, tags: t, legacyFactor: 10),
2020
BenchmarkInfo(name: "ArrayAppendArrayOfInt", runFunction: run_ArrayAppendArrayOfInt, tags: t,
2121
setUpFunction: ones, tearDownFunction: releaseOnes, legacyFactor: 10),
22-
BenchmarkInfo(name: "ArrayAppendAscii", runFunction: run_ArrayAppendAscii, tags: t, legacyFactor: 11),
23-
BenchmarkInfo(name: "ArrayAppendAsciiSubstring", runFunction: run_ArrayAppendAsciiSubstring, tags: t, legacyFactor: 11),
22+
BenchmarkInfo(name: "ArrayAppendAscii", runFunction: run_ArrayAppendAscii, tags: t, legacyFactor: 34),
23+
BenchmarkInfo(name: "ArrayAppendAsciiSubstring", runFunction: run_ArrayAppendAsciiSubstring, tags: t, legacyFactor: 36),
2424
BenchmarkInfo(name: "ArrayAppendFromGeneric", runFunction: run_ArrayAppendFromGeneric, tags: t,
2525
setUpFunction: ones, tearDownFunction: releaseOnes, legacyFactor: 10),
2626
BenchmarkInfo(name: "ArrayAppendGenericStructs", runFunction: run_ArrayAppendGenericStructs, tags: t,
2727
setUpFunction: { otherStructs = Array(repeating: S(x: 3, y: 4.2), count: 10_000) },
2828
tearDownFunction: { otherStructs = nil }, legacyFactor: 10),
29-
BenchmarkInfo(name: "ArrayAppendLatin1", runFunction: run_ArrayAppendLatin1, tags: t, legacyFactor: 11),
30-
BenchmarkInfo(name: "ArrayAppendLatin1Substring", runFunction: run_ArrayAppendLatin1Substring, tags: t, legacyFactor: 11),
29+
BenchmarkInfo(name: "ArrayAppendLatin1", runFunction: run_ArrayAppendLatin1, tags: t, legacyFactor: 34),
30+
BenchmarkInfo(name: "ArrayAppendLatin1Substring", runFunction: run_ArrayAppendLatin1Substring, tags: t, legacyFactor: 36),
3131
BenchmarkInfo(name: "ArrayAppendLazyMap", runFunction: run_ArrayAppendLazyMap, tags: t,
3232
setUpFunction: { blackHole(array) }, legacyFactor: 10),
3333
BenchmarkInfo(name: "ArrayAppendOptionals", runFunction: run_ArrayAppendOptionals, tags: t,
@@ -43,12 +43,12 @@ public let ArrayAppend = [
4343
setUpFunction: ones, tearDownFunction: releaseOnes, legacyFactor: 10),
4444
BenchmarkInfo(name: "ArrayAppendToGeneric", runFunction: run_ArrayAppendToGeneric, tags: t,
4545
setUpFunction: ones, tearDownFunction: releaseOnes, legacyFactor: 10),
46-
BenchmarkInfo(name: "ArrayAppendUTF16", runFunction: run_ArrayAppendUTF16, tags: t, legacyFactor: 11),
47-
BenchmarkInfo(name: "ArrayAppendUTF16Substring", runFunction: run_ArrayAppendUTF16Substring, tags: t, legacyFactor: 11),
46+
BenchmarkInfo(name: "ArrayAppendUTF16", runFunction: run_ArrayAppendUTF16, tags: t, legacyFactor: 34),
47+
BenchmarkInfo(name: "ArrayAppendUTF16Substring", runFunction: run_ArrayAppendUTF16Substring, tags: t, legacyFactor: 36),
4848
BenchmarkInfo(name: "ArrayPlusEqualArrayOfInt", runFunction: run_ArrayPlusEqualArrayOfInt, tags: t,
4949
setUpFunction: ones, tearDownFunction: releaseOnes, legacyFactor: 10),
50-
BenchmarkInfo(name: "ArrayPlusEqualFiveElementCollection", runFunction: run_ArrayPlusEqualFiveElementCollection, tags: t, legacyFactor: 49),
51-
BenchmarkInfo(name: "ArrayPlusEqualSingleElementCollection", runFunction: run_ArrayPlusEqualSingleElementCollection, tags: t, legacyFactor: 40),
50+
BenchmarkInfo(name: "ArrayPlusEqualFiveElementCollection", runFunction: run_ArrayPlusEqualFiveElementCollection, tags: t, legacyFactor: 37),
51+
BenchmarkInfo(name: "ArrayPlusEqualSingleElementCollection", runFunction: run_ArrayPlusEqualSingleElementCollection, tags: t, legacyFactor: 47),
5252
BenchmarkInfo(name: "ArrayPlusEqualThreeElements", runFunction: run_ArrayPlusEqualThreeElements, tags: t, legacyFactor: 10),
5353
]
5454

@@ -308,7 +308,7 @@ public func run_ArrayAppendAscii(_ N: Int) {
308308
let s = "the quick brown fox jumps over the lazy dog!"
309309
for _ in 0..<N {
310310
var nums = [UInt8]()
311-
for _ in 0..<10_000 {
311+
for _ in 0..<3_000 {
312312
nums += getString(s).utf8
313313
}
314314
}
@@ -320,7 +320,7 @@ public func run_ArrayAppendLatin1(_ N: Int) {
320320
let s = "the quick brown fox jumps over the lazy dog\u{00A1}"
321321
for _ in 0..<N {
322322
var nums = [UInt8]()
323-
for _ in 0..<10_000 {
323+
for _ in 0..<3_000 {
324324
nums += getString(s).utf8
325325
}
326326
}
@@ -332,7 +332,7 @@ public func run_ArrayAppendUTF16(_ N: Int) {
332332
let s = "the quick brown 🦊 jumps over the lazy dog"
333333
for _ in 0..<N {
334334
var nums = [UInt8]()
335-
for _ in 0..<10_000 {
335+
for _ in 0..<3_000 {
336336
nums += getString(s).utf8
337337
}
338338
}
@@ -344,7 +344,7 @@ public func run_ArrayAppendAsciiSubstring(_ N: Int) {
344344
let s = "the quick brown fox jumps over the lazy dog!"[...]
345345
for _ in 0..<N {
346346
var nums = [UInt8]()
347-
for _ in 0..<10_000 {
347+
for _ in 0..<3_000 {
348348
nums += getSubstring(s).utf8
349349
}
350350
}
@@ -356,7 +356,7 @@ public func run_ArrayAppendLatin1Substring(_ N: Int) {
356356
let s = "the quick brown fox jumps over the lazy dog\u{00A1}"[...]
357357
for _ in 0..<N {
358358
var nums = [UInt8]()
359-
for _ in 0..<10_000 {
359+
for _ in 0..<3_000 {
360360
nums += getSubstring(s).utf8
361361
}
362362
}
@@ -368,7 +368,7 @@ public func run_ArrayAppendUTF16Substring(_ N: Int) {
368368
let s = "the quick brown 🦊 jumps over the lazy dog"[...]
369369
for _ in 0..<N {
370370
var nums = [UInt8]()
371-
for _ in 0..<10_000 {
371+
for _ in 0..<3_000 {
372372
nums += getSubstring(s).utf8
373373
}
374374
}

0 commit comments

Comments
 (0)