Skip to content

Commit 7cb9489

Browse files
committed
Add binary floating-point properties benchmarks
1 parent 95e1558 commit 7cb9489

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(SWIFT_BENCH_MODULES
4141
single-source/ArraySetElement
4242
single-source/ArraySubscript
4343
single-source/BinaryFloatingPointConversionFromBinaryInteger
44+
single-source/BinaryFloatingPointProperties
4445
single-source/BitCount
4546
single-source/ByteSwap
4647
single-source/COWTree
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//===--- BinaryFloatingPointProperties.swift ------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Foundation
14+
import TestsUtils
15+
16+
public let BinaryFloatingPointPropertiesBinade = BenchmarkInfo(
17+
name: "BinaryFloatingPointPropertiesBinade",
18+
runFunction: run_BinaryFloatingPointPropertiesBinade,
19+
tags: [.validation, .algorithm]
20+
)
21+
22+
public let BinaryFloatingPointPropertiesNextUp = BenchmarkInfo(
23+
name: "BinaryFloatingPointPropertiesNextUp",
24+
runFunction: run_BinaryFloatingPointPropertiesNextUp,
25+
tags: [.validation, .algorithm]
26+
)
27+
28+
public let BinaryFloatingPointPropertiesUlp = BenchmarkInfo(
29+
name: "BinaryFloatingPointPropertiesUlp",
30+
runFunction: run_BinaryFloatingPointPropertiesUlp,
31+
tags: [.validation, .algorithm]
32+
)
33+
34+
@inline(never)
35+
public func run_BinaryFloatingPointPropertiesBinade(_ N: Int) {
36+
var xs = [Double]()
37+
xs.reserveCapacity(N)
38+
for _ in 1...N {
39+
var x = 0 as Double
40+
for i in 0..<10000 {
41+
x += Double(getInt(i)).binade
42+
}
43+
xs.append(x)
44+
}
45+
CheckResults(xs[getInt(0)] == 37180757)
46+
}
47+
48+
@inline(never)
49+
public func run_BinaryFloatingPointPropertiesNextUp(_ N: Int) {
50+
var xs = [Int]()
51+
xs.reserveCapacity(N)
52+
for _ in 1...N {
53+
var x = 0 as Int
54+
for i in 0..<10000 {
55+
x += Int(Double(getInt(i)).nextUp)
56+
}
57+
xs.append(x)
58+
}
59+
CheckResults(xs[getInt(0)] == 49995000)
60+
}
61+
62+
@inline(never)
63+
public func run_BinaryFloatingPointPropertiesUlp(_ N: Int) {
64+
var xs = [Int]()
65+
xs.reserveCapacity(N)
66+
for _ in 1...N {
67+
var x = 0 as Int
68+
for i in 0..<10000 {
69+
x += Int(Double(getInt(i)).ulp)
70+
}
71+
xs.append(x)
72+
}
73+
CheckResults(xs[getInt(0)] == 0)
74+
}

benchmark/utils/main.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import ArrayOfRef
2828
import ArraySetElement
2929
import ArraySubscript
3030
import BinaryFloatingPointConversionFromBinaryInteger
31+
import BinaryFloatingPointProperties
3132
import BitCount
3233
import ByteSwap
3334
import COWTree
@@ -169,6 +170,9 @@ registerBenchmark(ArrayOfRef)
169170
registerBenchmark(ArraySetElement)
170171
registerBenchmark(ArraySubscript)
171172
registerBenchmark(BinaryFloatingPointConversionFromBinaryInteger)
173+
registerBenchmark(BinaryFloatingPointPropertiesBinade)
174+
registerBenchmark(BinaryFloatingPointPropertiesNextUp)
175+
registerBenchmark(BinaryFloatingPointPropertiesUlp)
172176
registerBenchmark(BitCount)
173177
registerBenchmark(ByteSwap)
174178
registerBenchmark(COWTree)

0 commit comments

Comments
 (0)