Skip to content

Commit e127acd

Browse files
committed
[benchmark] DataAppendData refactored
Refactored to use shared test method and inlined runFunctions. Extracted setup overhead. Re-enabled `Large` tests errorneously disabled in #20411.
1 parent 21baf46 commit e127acd

File tree

1 file changed

+14
-76
lines changed

1 file changed

+14
-76
lines changed

benchmark/single-source/DataBenchmarks.swift

Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,23 @@ public let DataBenchmarks = [
9898
runFunction: run_AppendSequence, tags: d),
9999

100100
BenchmarkInfo(name: "DataAppendDataSmallToSmall",
101-
runFunction: run_AppendDataSmallToSmall, tags: d),
101+
runFunction: { append($0, data: small, to: small) }, tags: d),
102102
BenchmarkInfo(name: "DataAppendDataSmallToMedium",
103-
runFunction: run_AppendDataSmallToMedium, tags: d),
103+
runFunction: { append($0, data: small, to: medium) }, tags: d),
104104
BenchmarkInfo(name: "DataAppendDataSmallToLarge",
105-
runFunction: run_AppendDataSmallToLarge, tags: d),
105+
runFunction: { append($0, data: small, to: large) }, tags: d),
106106
BenchmarkInfo(name: "DataAppendDataMediumToSmall",
107-
runFunction: run_AppendDataMediumToSmall, tags: d),
107+
runFunction: { append($0, data: medium, to: small) }, tags: d),
108108
BenchmarkInfo(name: "DataAppendDataMediumToMedium",
109-
runFunction: run_AppendDataMediumToMedium, tags: d),
109+
runFunction: { append($0, data: medium, to: medium) }, tags: d),
110110
BenchmarkInfo(name: "DataAppendDataMediumToLarge",
111-
runFunction: run_AppendDataMediumToLarge, tags: skip),
111+
runFunction: { append($0, data: medium, to: large) }, tags: d),
112112
BenchmarkInfo(name: "DataAppendDataLargeToSmall",
113-
runFunction: run_AppendDataLargeToSmall, tags: d),
113+
runFunction: { append($0, data: large, to: small) }, tags: d),
114114
BenchmarkInfo(name: "DataAppendDataLargeToMedium",
115-
runFunction: run_AppendDataLargeToMedium, tags: d),
115+
runFunction: { append($0, data: large, to: medium) }, tags: d),
116116
BenchmarkInfo(name: "DataAppendDataLargeToLarge",
117-
runFunction: run_AppendDataLargeToLarge, tags: skip),
117+
runFunction: { append($0, data: large, to: large) }, tags: d),
118118

119119
BenchmarkInfo(name: "DataToStringEmpty",
120120
runFunction: run_DataToStringEmpty, tags: d, legacyFactor: 50),
@@ -260,11 +260,12 @@ func benchmark_ReplaceBuffer(_ N: Int, _ range: Range<Data.Index>, _ data_: Data
260260
}
261261
}
262262

263-
func benchmark_AppendData(_ N: Int, _ lhs: Data, _ rhs: Data) {
264-
var data = lhs
263+
@inline(never)
264+
func append(_ N: Int, data: Data, to target: Data) {
265+
var copy: Data
265266
for _ in 0..<10000*N {
266-
data = lhs
267-
data.append(rhs)
267+
copy = target
268+
copy.append(data)
268269
}
269270
}
270271

@@ -355,69 +356,6 @@ public func run_AppendSequence(_ N: Int) {
355356
benchmark_AppendSequence(N, 809, data)
356357
}
357358

358-
@inline(never)
359-
public func run_AppendDataSmallToSmall(_ N: Int) {
360-
let data = sampleData(.small)
361-
let other = sampleData(.small)
362-
benchmark_AppendData(N, data, other)
363-
}
364-
365-
@inline(never)
366-
public func run_AppendDataSmallToMedium(_ N: Int) {
367-
let data = sampleData(.medium)
368-
let other = sampleData(.small)
369-
benchmark_AppendData(N, data, other)
370-
}
371-
372-
@inline(never)
373-
public func run_AppendDataSmallToLarge(_ N: Int) {
374-
let data = sampleData(.large)
375-
let other = sampleData(.small)
376-
benchmark_AppendData(N, data, other)
377-
}
378-
379-
@inline(never)
380-
public func run_AppendDataMediumToSmall(_ N: Int) {
381-
let data = sampleData(.small)
382-
let other = sampleData(.medium)
383-
benchmark_AppendData(N, data, other)
384-
}
385-
386-
@inline(never)
387-
public func run_AppendDataMediumToMedium(_ N: Int) {
388-
let data = sampleData(.medium)
389-
let other = sampleData(.medium)
390-
benchmark_AppendData(N, data, other)
391-
}
392-
393-
@inline(never)
394-
public func run_AppendDataMediumToLarge(_ N: Int) {
395-
let data = sampleData(.large)
396-
let other = sampleData(.medium)
397-
benchmark_AppendData(N, data, other)
398-
}
399-
400-
@inline(never)
401-
public func run_AppendDataLargeToSmall(_ N: Int) {
402-
let data = sampleData(.small)
403-
let other = sampleData(.large)
404-
benchmark_AppendData(N, data, other)
405-
}
406-
407-
@inline(never)
408-
public func run_AppendDataLargeToMedium(_ N: Int) {
409-
let data = sampleData(.medium)
410-
let other = sampleData(.large)
411-
benchmark_AppendData(N, data, other)
412-
}
413-
414-
@inline(never)
415-
public func run_AppendDataLargeToLarge(_ N: Int) {
416-
let data = sampleData(.large)
417-
let other = sampleData(.large)
418-
benchmark_AppendData(N, data, other)
419-
}
420-
421359
@inline(never)
422360
public func run_DataToStringEmpty(_ N: Int) {
423361
let d = Data()

0 commit comments

Comments
 (0)