Skip to content

Commit 2a07c1c

Browse files
committed
[interop] benchmark: add run_CxxVectorOfU32_Sum_Swift_RawIteratorLoop that doesn't use C++ inline helpers
1 parent 157be05 commit 2a07c1c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

benchmark/cxx-source/CxxVectorSum.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public let benchmarks = [
3030
name: "CxxVectorOfU32.Sum.Swift.RawIteratorLoop",
3131
runFunction: run_CxxVectorOfU32_Sum_Swift_RawIteratorLoop,
3232
tags: [.validation, .bridging, .cxxInterop]),
33+
BenchmarkInfo(
34+
name: "CxxVectorOfU32.Sum.Swift.RawIteratorLoop.WithCxxInlineHelpers",
35+
runFunction: run_CxxVectorOfU32_Sum_Swift_RawIteratorLoop_WithCxxInlineHelpers,
36+
tags: [.validation, .bridging, .cxxInterop]),
3337
BenchmarkInfo(
3438
name: "CxxVectorOfU32.Sum.Swift.IndexAndSubscriptLoop",
3539
runFunction: run_CxxVectorOfU32_Sum_Swift_IndexAndSubscriptLoop,
@@ -68,7 +72,7 @@ public func run_CxxVectorOfU32_Sum_Swift_ForInLoop(_ n: Int) {
6872
// This function should have comparable performance to
6973
// `run_CxxVectorOfU32_Sum_Cxx_RangedForLoop`.
7074
@inline(never)
71-
public func run_CxxVectorOfU32_Sum_Swift_RawIteratorLoop(_ n: Int) {
75+
public func run_CxxVectorOfU32_Sum_Swift_RawIteratorLoop_WithCxxInlineHelpers(_ n: Int) {
7276
let vectorOfU32 = makeVector32(vectorSize)
7377
var sum: UInt32 = 0
7478
for _ in 0..<(n * iterRepeatFactor) {
@@ -82,6 +86,23 @@ public func run_CxxVectorOfU32_Sum_Swift_RawIteratorLoop(_ n: Int) {
8286
blackHole(sum)
8387
}
8488

89+
// This function should have comparable performance to
90+
// `run_CxxVectorOfU32_Sum_Cxx_RangedForLoop`.
91+
@inline(never)
92+
public func run_CxxVectorOfU32_Sum_Swift_RawIteratorLoop(_ n: Int) {
93+
let vectorOfU32 = makeVector32(vectorSize)
94+
var sum: UInt32 = 0
95+
for _ in 0..<(n * iterRepeatFactor) {
96+
var b = vectorOfU32.__beginUnsafe()
97+
let e = vectorOfU32.__endUnsafe()
98+
while b != e {
99+
sum = sum &+ b.pointee
100+
b = b.successor()
101+
}
102+
}
103+
blackHole(sum)
104+
}
105+
85106
@inline(never)
86107
public func run_CxxVectorOfU32_Sum_Swift_IndexAndSubscriptLoop(_ n: Int) {
87108
let vectorOfU32 = makeVector32(vectorSize)

0 commit comments

Comments
 (0)