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