Skip to content

Commit 9488774

Browse files
committed
[benchmark] Add another test to floating point conversion benchmark
1 parent 566a671 commit 9488774

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

benchmark/single-source/FloatingPointConversion.swift

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public let FloatingPointConversion = [
1818
runFunction: run_ConvertFloatingPoint_MockFloat64ToDouble,
1919
tags: [.validation, .api],
2020
setUpFunction: { blackHole(mockFloat64s) }),
21+
BenchmarkInfo(
22+
name: "ConvertFloatingPoint.MockFloat64Exactly",
23+
runFunction: run_ConvertFloatingPoint_MockFloat64Exactly,
24+
tags: [.validation, .api],
25+
setUpFunction: { blackHole(mockFloat64s) }),
2126
BenchmarkInfo(
2227
name: "ConvertFloatingPoint.MockFloat64ToInt64",
2328
runFunction: run_ConvertFloatingPoint_MockFloat64ToInt64,
@@ -147,20 +152,30 @@ let doubles = [
147152

148153
let mockFloat64s = doubles.map { MockFloat64($0) }
149154

155+
// See also: test/SILOptimizer/floating_point_conversion.swift
156+
157+
@inline(never)
158+
public func run_ConvertFloatingPoint_MockFloat64ToDouble(_ N: Int) {
159+
for _ in 0..<(N * 100) {
160+
for element in mockFloat64s {
161+
let f = Double(identity(element))
162+
blackHole(f)
163+
}
164+
}
165+
}
166+
150167
@inline(__always)
151168
func convert<
152169
T: BinaryFloatingPoint, U: BinaryFloatingPoint
153-
>(_ value: T, to: U.Type) -> U {
154-
U(value)
170+
>(exactly value: T, to: U.Type) -> U? {
171+
U(exactly: value)
155172
}
156173

157-
// See also: test/SILOptimizer/floating_point_conversion.swift
158-
159174
@inline(never)
160-
public func run_ConvertFloatingPoint_MockFloat64ToDouble(_ N: Int) {
175+
public func run_ConvertFloatingPoint_MockFloat64Exactly(_ N: Int) {
161176
for _ in 0..<(N * 100) {
162177
for element in mockFloat64s {
163-
let f = Double(identity(element))
178+
let f = convert(exactly: identity(element), to: Double.self)
164179
blackHole(f)
165180
}
166181
}

0 commit comments

Comments
 (0)