Skip to content

Commit f239f19

Browse files
committed
[benchmark] DataAppendArray refactored
Refactored to use shareable test method and inlined runFunction.
1 parent e127acd commit f239f19

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

benchmark/single-source/DataBenchmarks.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public let DataBenchmarks = [
7575
runFunction: { append($0, bytes: 809, to: medium) }, tags: d),
7676

7777
BenchmarkInfo(name: "DataAppendArray",
78-
runFunction: run_AppendArray, tags: d),
78+
runFunction: { append($0, arraySize: 809, to: medium) }, tags: d),
7979

8080
BenchmarkInfo(name: "DataReset",
8181
runFunction: run_Reset, tags: d),
@@ -220,14 +220,15 @@ func append(_ N: Int, bytes count: Int, to data: Data) {
220220
}
221221
}
222222

223-
func benchmark_AppendArray(_ N: Int, _ count: Int, _ data_: Data) {
224-
var bytes = [UInt8](repeating: 0, count: count)
223+
@inline(never)
224+
func append(_ N: Int, arraySize: Int, to data: Data) {
225+
var bytes = [UInt8](repeating: 0, count: arraySize)
225226
bytes.withUnsafeMutableBufferPointer {
226227
fillBuffer($0)
227228
}
228229
for _ in 0..<10000*N {
229-
var data = data_
230-
data.append(contentsOf: bytes)
230+
var copy = data
231+
copy.append(contentsOf: bytes)
231232
}
232233
}
233234

@@ -287,12 +288,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) {
287288
}
288289
}
289290

290-
@inline(never)
291-
public func run_AppendArray(_ N: Int) {
292-
let data = sampleData(.medium)
293-
benchmark_AppendArray(N, 809, data)
294-
}
295-
296291
@inline(never)
297292
public func run_Reset(_ N: Int) {
298293
let data = sampleData(.medium)

0 commit comments

Comments
 (0)