Skip to content

Commit 464b585

Browse files
committed
Update benchmark to be more similar to other devirtualization benchmarks
1 parent 209bfd0 commit 464b585

File tree

1 file changed

+11
-31
lines changed

1 file changed

+11
-31
lines changed

benchmark/single-source/DevirtualizeProtocolComposition.swift

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,30 @@ public let DevirtualizeProtocolComposition = [
1616
BenchmarkInfo(name: "DevirtualizeProtocolComposition", runFunction: run_DevirtualizeProtocolComposition, tags: [.validation, .api]),
1717
]
1818

19-
public class ClassA<T> { }
19+
protocol Pingable { func ping() -> Int; func pong() -> Int}
2020

21-
protocol ProtocolA {
22-
func foo() -> Int
21+
public class Game<T> {
22+
func length() -> Int { return 10 }
2323
}
2424

25-
protocol ProtocolB {
26-
func bar() -> Int
27-
}
25+
public class PingPong: Game<String> { }
2826

29-
public class ClassB: ClassA<String> {
30-
func foo() -> Int {
31-
return 10
32-
}
27+
extension PingPong : Pingable {
28+
func ping() -> Int { return 1 }
29+
func pong() -> Int { return 2 }
3330
}
3431

35-
extension ClassB: ProtocolA { }
36-
37-
func quadratic(a: Int) -> Int {
32+
func playGame<T>(_ x: Game<T> & Pingable) -> Int {
3833
var sum = 0
39-
for _ in 0..<a {
40-
for _ in 0..<a {
41-
sum += 1
42-
}
34+
for _ in 0..<x.length() {
35+
sum += x.ping() + x.pong()
4336
}
4437
return sum
4538
}
4639

47-
func shouldOptimize1<T>(_ x: ClassA<T> & ProtocolA, count: Int) -> Int {
48-
var sum = 0
49-
for _ in 0..<count {
50-
sum += quadratic(a: x.foo())
51-
}
52-
return sum
53-
}
54-
55-
@inline(never)
56-
public func entryPoint1(c: ClassB) -> Int {
57-
return shouldOptimize1(c, count: 25)
58-
}
59-
6040
@inline(never)
6141
public func run_DevirtualizeProtocolComposition(N: Int) {
6242
for _ in 0..<N * 20_000 {
63-
blackHole(entryPoint1(c: ClassB()))
43+
blackHole(playGame(PingPong()))
6444
}
6545
}

0 commit comments

Comments
 (0)