Skip to content

Commit 26c498c

Browse files
author
Max Moiseev
committed
[benchmark] Add RangeIteration benchmarks
1 parent 41aa442 commit 26c498c

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ set(SWIFT_BENCH_MODULES
103103
single-source/RC4
104104
single-source/RGBHistogram
105105
single-source/RangeAssignment
106+
single-source/RangeIteration
106107
single-source/RecursiveOwnedParameter
107108
single-source/ReduceInto
108109
single-source/ReversedCollections
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import ProtocolDispatch2
9696
import RC4
9797
import RGBHistogram
9898
import RangeAssignment
99+
import RangeIteration
99100
import RecursiveOwnedParameter
100101
import ReduceInto
101102
import ReversedCollections
@@ -214,6 +215,7 @@ registerBenchmark(ProtocolDispatch2)
214215
registerBenchmark(RC4Test)
215216
registerBenchmark(RGBHistogram)
216217
registerBenchmark(RangeAssignment)
218+
registerBenchmark(RangeIteration)
217219
registerBenchmark(RecursiveOwnedParameter)
218220
registerBenchmark(ReduceInto)
219221
registerBenchmark(ReversedCollections)

0 commit comments

Comments
 (0)