Skip to content

[benchmark] Add binary floating-point properties benchmarks #14988

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 1 commit into from
Mar 6, 2018
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
1 change: 1 addition & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(SWIFT_BENCH_MODULES
single-source/ArraySetElement
single-source/ArraySubscript
single-source/BinaryFloatingPointConversionFromBinaryInteger
single-source/BinaryFloatingPointProperties
single-source/BitCount
single-source/ByteSwap
single-source/COWTree
Expand Down
74 changes: 74 additions & 0 deletions benchmark/single-source/BinaryFloatingPointProperties.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//===--- BinaryFloatingPointProperties.swift ------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation
import TestsUtils

public let BinaryFloatingPointPropertiesBinade = BenchmarkInfo(
name: "BinaryFloatingPointPropertiesBinade",
runFunction: run_BinaryFloatingPointPropertiesBinade,
tags: [.validation, .algorithm]
)

public let BinaryFloatingPointPropertiesNextUp = BenchmarkInfo(
name: "BinaryFloatingPointPropertiesNextUp",
runFunction: run_BinaryFloatingPointPropertiesNextUp,
tags: [.validation, .algorithm]
)

public let BinaryFloatingPointPropertiesUlp = BenchmarkInfo(
name: "BinaryFloatingPointPropertiesUlp",
runFunction: run_BinaryFloatingPointPropertiesUlp,
tags: [.validation, .algorithm]
)

@inline(never)
public func run_BinaryFloatingPointPropertiesBinade(_ N: Int) {
var xs = [Double]()
xs.reserveCapacity(N)
for _ in 1...N {
var x = 0 as Double
for i in 0..<10000 {
x += Double(getInt(i)).binade
}
xs.append(x)
}
CheckResults(xs[getInt(0)] == 37180757)
}

@inline(never)
public func run_BinaryFloatingPointPropertiesNextUp(_ N: Int) {
var xs = [Int]()
xs.reserveCapacity(N)
for _ in 1...N {
var x = 0 as Int
for i in 0..<10000 {
x += Int(Double(getInt(i)).nextUp)
}
xs.append(x)
}
CheckResults(xs[getInt(0)] == 49995000)
}

@inline(never)
public func run_BinaryFloatingPointPropertiesUlp(_ N: Int) {
var xs = [Int]()
xs.reserveCapacity(N)
for _ in 1...N {
var x = 0 as Int
for i in 0..<10000 {
x += Int(Double(getInt(i)).ulp)
}
xs.append(x)
}
CheckResults(xs[getInt(0)] == 0)
}
4 changes: 4 additions & 0 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import ArrayOfRef
import ArraySetElement
import ArraySubscript
import BinaryFloatingPointConversionFromBinaryInteger
import BinaryFloatingPointProperties
import BitCount
import ByteSwap
import COWTree
Expand Down Expand Up @@ -169,6 +170,9 @@ registerBenchmark(ArrayOfRef)
registerBenchmark(ArraySetElement)
registerBenchmark(ArraySubscript)
registerBenchmark(BinaryFloatingPointConversionFromBinaryInteger)
registerBenchmark(BinaryFloatingPointPropertiesBinade)
registerBenchmark(BinaryFloatingPointPropertiesNextUp)
registerBenchmark(BinaryFloatingPointPropertiesUlp)
registerBenchmark(BitCount)
registerBenchmark(ByteSwap)
registerBenchmark(COWTree)
Expand Down