Skip to content

Commit 26f3c81

Browse files
committed
[benchmark] Add another floating point conversion benchmark
1 parent 9488774 commit 26f3c81

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

benchmark/single-source/FloatingPointConversion.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public let FloatingPointConversion = [
2323
runFunction: run_ConvertFloatingPoint_MockFloat64Exactly,
2424
tags: [.validation, .api],
2525
setUpFunction: { blackHole(mockFloat64s) }),
26+
BenchmarkInfo(
27+
name: "ConvertFloatingPoint.MockFloat64Exactly.bis",
28+
runFunction: run_ConvertFloatingPoint_MockFloat64Exactly_bis,
29+
tags: [.validation, .api],
30+
setUpFunction: { blackHole(mockFloat64s) }),
2631
BenchmarkInfo(
2732
name: "ConvertFloatingPoint.MockFloat64ToInt64",
2833
runFunction: run_ConvertFloatingPoint_MockFloat64ToInt64,
@@ -135,6 +140,11 @@ struct MockFloat64: MockBinaryFloatingPoint {
135140
init(_ _value: Double) { self._value = _value }
136141
}
137142

143+
struct MockFloat32: MockBinaryFloatingPoint {
144+
var _value: Float
145+
init(_ _value: Float) { self._value = _value }
146+
}
147+
138148
let doubles = [
139149
1.8547832857295, 26.321549267719135, 98.9544480962058, 73.70286973782363,
140150
82.04918555938816, 76.38902969312758, 46.35647857011161, 64.0821426030317,
@@ -181,6 +191,16 @@ public func run_ConvertFloatingPoint_MockFloat64Exactly(_ N: Int) {
181191
}
182192
}
183193

194+
@inline(never)
195+
public func run_ConvertFloatingPoint_MockFloat64Exactly_bis(_ N: Int) {
196+
for _ in 0..<(N * 100) {
197+
for element in mockFloat64s {
198+
let f = convert(exactly: identity(element), to: MockFloat32.self)
199+
blackHole(f)
200+
}
201+
}
202+
}
203+
184204
@inline(never)
185205
public func run_ConvertFloatingPoint_MockFloat64ToInt64(_ N: Int) {
186206
for _ in 0..<(N * 1000) {

0 commit comments

Comments
 (0)