Skip to content

Commit 0eae9ea

Browse files
authored
Merge pull request #12070 from atrick/benchinfo
2 parents 4e4f5ae + 78b072b commit 0eae9ea

File tree

6 files changed

+71
-14
lines changed

6 files changed

+71
-14
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(SWIFT_BENCH_MODULES
2525
single-source/ArrayOfGenericRef
2626
single-source/ArrayOfPOD
2727
single-source/ArrayOfRef
28+
single-source/ArraySetElement
2829
single-source/ArraySubscript
2930
single-source/BitCount
3031
single-source/ByteSwap
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- ArraySetElement.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+
// 33% isUniquelyReferenced
16+
// 15% swift_rt_swift_isUniquelyReferencedOrPinned_nonNull_native
17+
// 18% swift_isUniquelyReferencedOrPinned_nonNull_native
18+
public var ArraySetElement = BenchmarkInfo(
19+
name: "ArraySetElement",
20+
runFunction: run_ArraySetElement,
21+
tags: [.runtime, .cpubench]
22+
)
23+
24+
// This is an effort to defeat isUniquelyReferenced optimization. Ideally
25+
// microbenchmarks list this should be written in C.
26+
@inline(never)
27+
func storeArrayElement(_ array: inout [Int], _ i: Int) {
28+
array[i] = i
29+
}
30+
31+
public func run_ArraySetElement(_ N: Int) {
32+
let scale = 10
33+
var array = [Int](repeating: 0, count: 10000)
34+
for _ in 0..<N*scale {
35+
for i in 0..<array.count {
36+
storeArrayElement(&array, i)
37+
}
38+
}
39+
}

benchmark/single-source/ObjectAllocation.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
import TestsUtils
1414

1515
// This test checks the performance of allocations.
16+
// 53% _swift_release_dealloc
17+
// 30% _swift_alloc_object
18+
// 10% retain/release
1619
public var ObjectAllocation = BenchmarkInfo(
1720
name: "ObjectAllocation",
1821
runFunction: run_ObjectAllocation,
19-
tags: [.runtime]
22+
tags: [.runtime, .cpubench]
2023
)
2124

2225
final class XX {

benchmark/utils/DriverUtils.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ struct TestConfig {
182182
if onlyRegistered {
183183
allTests = registeredBenchmarks.map {
184184
bench -> (key: String, value: (Int)-> ()) in
185-
(bench.name, bench.runFunction)
185+
return (bench.name, bench.runFunction)
186186
}
187+
// FIXME: for now unstable/extra benchmarks are not registered at all, but
188+
// soon they will be handled with a default exclude list.
189+
onlyPrecommit = false
187190
}
188191
else {
189192
allTests = [precommitTests, otherTests, stringTests]

benchmark/utils/TestsUtils.swift

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ import Darwin
1717
#endif
1818

1919
public enum BenchmarkCategories {
20-
// Optimized benchmarks cover performance areas that have already been
21-
// investigated and optimized to some reasonable level. We expect these to be
22-
// "representative" of Swift perforance.
23-
case optimized
24-
25-
// Most benchmarks are assumed to be "stable" and will be regularly tracked at
26-
// each commit. A handful may be marked unstable if continually tracking them is
27-
// counterproductive.
28-
case unstable
29-
3020
// Validation "micro" benchmarks test a specific operation or critical path that
3121
// we know is important to measure.
3222
case validation
@@ -53,9 +43,28 @@ case miniapplication
5343
// report. We want to make sure the optimizer as a whole continues to handle
5444
// this case, but don't know how applicable it is to general Swift performance
5545
// relative to the other micro-benchmarks. In particular, these aren't weighted
56-
// as highly as "validation" benchmarks and likely won't be the subject of future
57-
// investigation unless they significantly regress.
46+
// as highly as "validation" benchmarks and likely won't be the subject of
47+
// future investigation unless they significantly regress.
5848
case regression
49+
50+
// Most benchmarks are assumed to be "stable" and will be regularly tracked at
51+
// each commit. A handful may be marked unstable if continually tracking them is
52+
// counterproductive.
53+
case unstable
54+
55+
// CPU benchmarks represent instrinsic Swift performance. They are useful for
56+
// measuring a fully baked Swift implementation across different platforms and
57+
// hardware. The benchmark should also be reasonably applicable to real Swift
58+
// code--it should exercise a known performance critical area. Typically these
59+
// will be drawn from the validation benchmarks once the language and standard
60+
// library implementation of the benchmark meets a reasonable efficiency
61+
// baseline. A benchmark should only be tagged "cpubench" after a full
62+
// performance investigation of the benchmark has been completed to determine
63+
// that it is a good representation of future Swift performance. Benchmarks
64+
// should not be tagged if they make use of an API that we plan on
65+
// reimplementing or call into code paths that have known opportunities for
66+
// significant optimization.
67+
case cpubench
5968
}
6069

6170
public struct BenchmarkInfo {

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import ArrayOfGenericPOD
3030
import ArrayOfGenericRef
3131
import ArrayOfPOD
3232
import ArrayOfRef
33+
import ArraySetElement
3334
import ArraySubscript
3435
import BitCount
3536
import ByteSwap
@@ -137,6 +138,7 @@ private func registerBenchmark(_ bench: BenchmarkInfo) {
137138
registeredBenchmarks.append(bench)
138139
}
139140

141+
registerBenchmark(ArraySetElement)
140142
registerBenchmark(ObjectAllocation)
141143

142144
// The main test suite: precommit tests

0 commit comments

Comments
 (0)