Skip to content

Commit 003d601

Browse files
authored
Merge pull request #22556 from palimondo/a-tall-white-fountain-played
[benchmark] Janitor Duty: Sweep I
2 parents 7d6af90 + 93adef9 commit 003d601

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

benchmark/single-source/ArrayLiteral.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import TestsUtils
1717

1818
public let ArrayLiteral = [
19-
BenchmarkInfo(name: "ArrayLiteral", runFunction: run_ArrayLiteral, tags: [.validation, .api, .Array]),
19+
BenchmarkInfo(name: "ArrayLiteral2", runFunction: run_ArrayLiteral, tags: [.validation, .api, .Array]),
2020
BenchmarkInfo(name: "ArrayValueProp", runFunction: run_ArrayValueProp, tags: [.validation, .api, .Array]),
2121
BenchmarkInfo(name: "ArrayValueProp2", runFunction: run_ArrayValueProp2, tags: [.validation, .api, .Array]),
2222
BenchmarkInfo(name: "ArrayValueProp3", runFunction: run_ArrayValueProp3, tags: [.validation, .api, .Array]),
@@ -31,7 +31,7 @@ func makeArray() -> [Int] {
3131
@inline(never)
3232
public func run_ArrayLiteral(_ N: Int) {
3333
for _ in 1...10000*N {
34-
_ = makeArray()
34+
blackHole(makeArray())
3535
}
3636
}
3737

benchmark/single-source/ArraySetElement.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import TestsUtils
1818
public var ArraySetElement = BenchmarkInfo(
1919
name: "ArraySetElement",
2020
runFunction: run_ArraySetElement,
21-
tags: [.runtime, .cpubench, .unstable],
22-
legacyFactor: 10
21+
tags: [.runtime, .cpubench]
2322
)
2423

2524
// This is an effort to defeat isUniquelyReferenced optimization. Ideally
@@ -31,7 +30,7 @@ func storeArrayElement(_ array: inout [Int], _ i: Int) {
3130

3231
public func run_ArraySetElement(_ N: Int) {
3332
var array = [Int](repeating: 0, count: 10000)
34-
for _ in 0..<N {
33+
for _ in 0..<10*N {
3534
for i in 0..<array.count {
3635
storeArrayElement(&array, i)
3736
}

benchmark/single-source/DataBenchmarks.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public let DataBenchmarks = [
9090
legacyFactor: 20),
9191

9292
BenchmarkInfo(name: "DataAppendArray",
93-
runFunction: { append($0*100, arraySize: 809, to: medium) }, tags: d,
93+
runFunction: { append($0*100, array: array809, to: medium) }, tags: d,
9494
legacyFactor: 100),
9595

9696
BenchmarkInfo(name: "DataReset",
@@ -203,6 +203,8 @@ let small = sampleData(.small)
203203
let medium = sampleData(.medium)
204204
let large = sampleData(.large)
205205

206+
let array809 = byteArray(size: 809)
207+
206208
let repeatElementSeq = { count in
207209
return sequence(state: count) { (i: inout Int) -> UInt8? in
208210
defer { i = i &- 1 }; return i > 0 ? UInt8(0xA0) : nil
@@ -217,10 +219,14 @@ enum SampleKind {
217219
case immutableBacking
218220
}
219221

220-
func fillBuffer(_ buffer: UnsafeMutableBufferPointer<UInt8>) {
221-
for i in buffer.indices {
222-
buffer[i] = UInt8(truncatingIfNeeded: i)
222+
func byteArray(size: Int) -> [UInt8] {
223+
var bytes = [UInt8](repeating: 0, count: size)
224+
bytes.withUnsafeMutableBufferPointer { buffer in
225+
for i in buffer.indices {
226+
buffer[i] = UInt8(truncatingIfNeeded: i)
227+
}
223228
}
229+
return bytes
224230
}
225231

226232
func sampleData(size: Int) -> Data {
@@ -235,11 +241,7 @@ func sampleData(size: Int) -> Data {
235241

236242
func sampleBridgedNSData() -> Data {
237243
let count = 1033
238-
var bytes = [UInt8](repeating: 0, count: count)
239-
bytes.withUnsafeMutableBufferPointer {
240-
fillBuffer($0)
241-
}
242-
let data = NSData(bytes: bytes, length: count)
244+
let data = NSData(bytes: byteArray(size: count), length: count)
243245
return Data(referencing: data)
244246
}
245247

@@ -295,11 +297,7 @@ func append(_ N: Int, bytes count: Int, to data: Data) {
295297
}
296298

297299
@inline(never)
298-
func append(_ N: Int, arraySize: Int, to data: Data) {
299-
var bytes = [UInt8](repeating: 0, count: arraySize)
300-
bytes.withUnsafeMutableBufferPointer {
301-
fillBuffer($0)
302-
}
300+
func append(_ N: Int, array bytes: [UInt8], to data: Data) {
303301
for _ in 1...N {
304302
var copy = data
305303
copy.append(contentsOf: bytes)

0 commit comments

Comments
 (0)