Skip to content

Commit 1466b29

Browse files
committed
[benchmark] Disable one benchmark when compiling on Linux.
I was able to run Benchmark_QuickCheck with the out of tree Linux build with just these tests disabled and everything seems to work. rdar://40541972
1 parent fab1630 commit 1466b29

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

benchmark/single-source/DataBenchmarks.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ enum SampleKind {
5252

5353
func sampleData(size: Int) -> Data {
5454
var data = Data(count: size)
55-
data.withUnsafeMutableBytes { arc4random_buf($0, size) }
55+
data.withUnsafeMutableBytes { getRandomBuf(baseAddress: $0, count: size) }
5656
return data
5757
}
5858

@@ -89,11 +89,33 @@ func sampleString() -> Data {
8989
return Data(bytes: bytes)
9090
}
9191

92+
#if os(Linux)
93+
import Glibc
94+
#endif
95+
96+
@inline(__always)
97+
func getRandomBuf(_ arg: UnsafeMutableBufferPointer<UInt8>) {
98+
#if os(Linux)
99+
getrandom(arg.baseAddress, arg.count, 0)
100+
#else
101+
arc4random_buf(arg.baseAddress, arg.count)
102+
#endif
103+
}
104+
105+
@inline(__always)
106+
func getRandomBuf(baseAddress: UnsafeMutablePointer<UInt8>, count: Int) {
107+
#if os(Linux)
108+
getrandom(arg.baseAddress, arg.count, 0)
109+
#else
110+
arc4random_buf(baseAddress, count)
111+
#endif
112+
}
113+
92114
func sampleBridgedNSData() -> Data {
93115
let count = 1033
94116
var bytes = [UInt8](repeating: 0, count: count)
95117
bytes.withUnsafeMutableBufferPointer {
96-
arc4random_buf($0.baseAddress, $0.count)
118+
getRandomBuf($0)
97119
}
98120
let data = NSData(bytes: bytes, length: count)
99121
return Data(referencing: data)
@@ -151,7 +173,7 @@ func benchmark_AppendBytes(_ N: Int, _ count: Int, _ data_: Data) {
151173
func benchmark_AppendArray(_ N: Int, _ count: Int, _ data_: Data) {
152174
var bytes = [UInt8](repeating: 0, count: count)
153175
bytes.withUnsafeMutableBufferPointer {
154-
arc4random_buf($0.baseAddress, $0.count)
176+
getRandomBuf($0)
155177
}
156178
for _ in 1...10000*N {
157179
var data = data_

benchmark/single-source/DictionaryKeysContains.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,22 @@ public let DictionaryKeysContains = [
3737
runFunction: run_DictionaryKeysContains,
3838
tags: [.validation, .api, .Dictionary],
3939
setUpFunction: setup_DictionaryKeysContainsNative,
40-
tearDownFunction: teardown_DictionaryKeysContains),
40+
tearDownFunction: teardown_DictionaryKeysContains,
41+
unsupportedPlatforms: [.linux]),
4142
]
4243
#endif
4344

4445
private var dictionary: [NSString: NSString]!
4546

4647
private func setup_DictionaryKeysContainsNative() {
48+
#if os(Linux)
49+
fatalError("Unsupported benchmark")
50+
#else
4751
let keyValuePairs = (1...1_000_000).map {
4852
("\($0)" as NSString, "\($0)" as NSString)
4953
}
5054
dictionary = [NSString: NSString](uniqueKeysWithValues: keyValuePairs)
55+
#endif
5156
}
5257

5358
#if _runtime(_ObjC)
@@ -68,9 +73,13 @@ private func teardown_DictionaryKeysContains() {
6873

6974
@inline(never)
7075
public func run_DictionaryKeysContains(_ N: Int) {
76+
#if os(Linux)
77+
fatalError("Unsupported benchmark")
78+
#else
7179
for _ in 0..<(N * 100) {
7280
CheckResults(dictionary.keys.contains("42"))
7381
CheckResults(!dictionary.keys.contains("-1"))
7482
}
83+
#endif
7584
}
7685

0 commit comments

Comments
 (0)