Skip to content

Commit 6266dba

Browse files
committed
RangeIteration benchmark: remove global variable access from the critical path.
This benchmark was "accidentally" accessing a global variable in the main iteration loop, which is in some situations very expensive and has nothing to do with what the benchmark is trying to test.
1 parent 656fe89 commit 6266dba

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

benchmark/single-source/RangeIteration.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public let RangeIteration = [
4040
]
4141
#endif
4242

43-
public var check: UInt64 = 0
44-
4543
@inline(never)
4644
func sum(_ x: UInt64, _ y: UInt64) -> UInt64 {
4745
return x &+ y
@@ -50,7 +48,7 @@ func sum(_ x: UInt64, _ y: UInt64) -> UInt64 {
5048
@inline(never)
5149
public func run_RangeIterationSigned(_ N: Int) {
5250
let range = 0..<100000
53-
check = 0
51+
var check: UInt64 = 0
5452
for _ in 1...N {
5553
for e in range {
5654
check = sum(check, UInt64(e))
@@ -65,7 +63,7 @@ public func run_RangeIterationSigned(_ N: Int) {
6563
@inline(never)
6664
public func run_RangeIterationSigned64(_ N: Int) {
6765
let range: Range<Int64> = 0..<100000
68-
check = 0
66+
var check: UInt64 = 0
6967
for _ in 1...N {
7068
for e in range {
7169
check = sum(check, UInt64(e))
@@ -78,7 +76,7 @@ public func run_RangeIterationSigned64(_ N: Int) {
7876
@inline(never)
7977
public func run_RangeIterationUnsigned(_ N: Int) {
8078
let range: Range<UInt> = 0..<100000
81-
check = 0
79+
var check: UInt64 = 0
8280
for _ in 1...N {
8381
for e in range {
8482
check = sum(check, UInt64(e))

0 commit comments

Comments
 (0)