1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
//===--- RangeAssignment.swift --------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 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 TestsUtils
#if swift(>=4.2)
public let benchmarks = [
BenchmarkInfo(
name: "RangeIterationSigned",
runFunction: run_RangeIterationSigned,
tags: [.validation, .api]
),
BenchmarkInfo(
name: "RangeIterationSigned64",
runFunction: run_RangeIterationSigned64,
tags: [.validation, .api]
),
BenchmarkInfo(
name: "RangeIterationUnsigned",
runFunction: run_RangeIterationUnsigned,
tags: [.validation, .api]
),
]
#else
public let benchmarks = [
BenchmarkInfo(
name: "RangeIterationSigned",
runFunction: run_RangeIterationSigned,
tags: [.validation, .api]
)
]
#endif
@inline(never)
func sum(_ x: UInt64, _ y: UInt64) -> UInt64 {
return x &+ y
}
@inline(never)
public func run_RangeIterationSigned(_ n: Int) {
let range = 0..<100000
var checksum: UInt64 = 0
for _ in 1...n {
for e in range {
checksum = sum(checksum, UInt64(e))
}
}
check(checksum == 4999950000 * UInt64(n))
}
#if swift(>=4.2)
@inline(never)
public func run_RangeIterationSigned64(_ n: Int) {
let range: Range<Int64> = 0..<100000
var check: UInt64 = 0
for _ in 1...n {
for e in range {
check = sum(check, UInt64(e))
}
}
check(check == 4999950000 * UInt64(n))
}
@inline(never)
public func run_RangeIterationUnsigned(_ n: Int) {
let range: Range<UInt> = 0..<100000
var check: UInt64 = 0
for _ in 1...n {
for e in range {
check = sum(check, UInt64(e))
}
}
check(check == 4999950000 * UInt64(n))
}
#endif
|