Skip to content

Commit ad82fe6

Browse files
authored
Merge pull request #16828 from gottesmm/pr-84e7c044a8d49ddcb70f6fc1535e1309e96c6a27
[func-sig-opts] Add a regression benchmark that shows overhead from +…
2 parents d9a65f4 + 1d5aca4 commit ad82fe6

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ set(SWIFT_BENCH_MODULES
4545
single-source/BitCount
4646
single-source/ByteSwap
4747
single-source/COWTree
48+
single-source/COWArrayGuaranteedParameterOverhead
4849
single-source/CString
4950
single-source/CSVParsing
5051
single-source/Calculator
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===--- COWArrayGuaranteedParameterOverhead.swift ------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 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+
// This test makes sure that even though we have +0 arguments by default that we
16+
// can properly convert +0 -> +1 to avoid extra COW copies.
17+
18+
public let COWArrayGuaranteedParameterOverhead = BenchmarkInfo(
19+
name: "COWArrayGuaranteedParameterOverhead",
20+
runFunction: run_COWArrayGuaranteedParameterOverhead,
21+
tags: [.regression, .abstraction, .refcount])
22+
23+
@inline(never)
24+
func caller() {
25+
let x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
26+
blackHole(callee(x))
27+
}
28+
29+
@inline(never)
30+
func callee(_ x: [Int]) -> [Int] {
31+
var y = x
32+
// This should not copy.
33+
y[2] = 27
34+
return y
35+
}
36+
37+
@inline(never)
38+
public func run_COWArrayGuaranteedParameterOverhead(_ N: Int) {
39+
for _ in 0..<N*20000 {
40+
caller()
41+
}
42+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import BinaryFloatingPointProperties
3232
import BitCount
3333
import ByteSwap
3434
import COWTree
35+
import COWArrayGuaranteedParameterOverhead
3536
import CString
3637
import CSVParsing
3738
import Calculator
@@ -184,6 +185,7 @@ registerBenchmark(BinaryFloatingPointPropertiesUlp)
184185
registerBenchmark(BitCount)
185186
registerBenchmark(ByteSwap)
186187
registerBenchmark(COWTree)
188+
registerBenchmark(COWArrayGuaranteedParameterOverhead)
187189
registerBenchmark(CString)
188190
registerBenchmark(CSVParsing)
189191
registerBenchmark(CSVParsingAlt)

0 commit comments

Comments
 (0)