Skip to content

[benchmark] Janitor Duty: Sweep I #22556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmark/single-source/ArrayLiteral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import TestsUtils

public let ArrayLiteral = [
BenchmarkInfo(name: "ArrayLiteral", runFunction: run_ArrayLiteral, tags: [.validation, .api, .Array]),
BenchmarkInfo(name: "ArrayLiteral2", runFunction: run_ArrayLiteral, tags: [.validation, .api, .Array]),
BenchmarkInfo(name: "ArrayValueProp", runFunction: run_ArrayValueProp, tags: [.validation, .api, .Array]),
BenchmarkInfo(name: "ArrayValueProp2", runFunction: run_ArrayValueProp2, tags: [.validation, .api, .Array]),
BenchmarkInfo(name: "ArrayValueProp3", runFunction: run_ArrayValueProp3, tags: [.validation, .api, .Array]),
Expand All @@ -31,7 +31,7 @@ func makeArray() -> [Int] {
@inline(never)
public func run_ArrayLiteral(_ N: Int) {
for _ in 1...10000*N {
_ = makeArray()
blackHole(makeArray())
}
}

Expand Down
5 changes: 2 additions & 3 deletions benchmark/single-source/ArraySetElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import TestsUtils
public var ArraySetElement = BenchmarkInfo(
name: "ArraySetElement",
runFunction: run_ArraySetElement,
tags: [.runtime, .cpubench, .unstable],
legacyFactor: 10
tags: [.runtime, .cpubench]
)

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

public func run_ArraySetElement(_ N: Int) {
var array = [Int](repeating: 0, count: 10000)
for _ in 0..<N {
for _ in 0..<10*N {
for i in 0..<array.count {
storeArrayElement(&array, i)
}
Expand Down
26 changes: 12 additions & 14 deletions benchmark/single-source/DataBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public let DataBenchmarks = [
legacyFactor: 20),

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

BenchmarkInfo(name: "DataReset",
Expand Down Expand Up @@ -194,6 +194,8 @@ let small = sampleData(.small)
let medium = sampleData(.medium)
let large = sampleData(.large)

let array809 = byteArray(size: 809)

let repeatElementSeq = { count in
return sequence(state: count) { (i: inout Int) -> UInt8? in
defer { i = i &- 1 }; return i > 0 ? UInt8(0xA0) : nil
Expand All @@ -208,10 +210,14 @@ enum SampleKind {
case immutableBacking
}

func fillBuffer(_ buffer: UnsafeMutableBufferPointer<UInt8>) {
for i in buffer.indices {
buffer[i] = UInt8(truncatingIfNeeded: i)
func byteArray(size: Int) -> [UInt8] {
var bytes = [UInt8](repeating: 0, count: size)
bytes.withUnsafeMutableBufferPointer { buffer in
for i in buffer.indices {
buffer[i] = UInt8(truncatingIfNeeded: i)
}
}
return bytes
}

func sampleData(size: Int) -> Data {
Expand All @@ -226,11 +232,7 @@ func sampleData(size: Int) -> Data {

func sampleBridgedNSData() -> Data {
let count = 1033
var bytes = [UInt8](repeating: 0, count: count)
bytes.withUnsafeMutableBufferPointer {
fillBuffer($0)
}
let data = NSData(bytes: bytes, length: count)
let data = NSData(bytes: byteArray(size: count), length: count)
return Data(referencing: data)
}

Expand Down Expand Up @@ -286,11 +288,7 @@ func append(_ N: Int, bytes count: Int, to data: Data) {
}

@inline(never)
func append(_ N: Int, arraySize: Int, to data: Data) {
var bytes = [UInt8](repeating: 0, count: arraySize)
bytes.withUnsafeMutableBufferPointer {
fillBuffer($0)
}
func append(_ N: Int, array bytes: [UInt8], to data: Data) {
for _ in 1...N {
var copy = data
copy.append(contentsOf: bytes)
Expand Down