Skip to content

Commit 9c5a66a

Browse files
authored
Merge pull request swiftlang#12074 from atrick/benchinfo
2 parents 611fb49 + 7a4adbe commit 9c5a66a

File tree

7 files changed

+136
-56
lines changed

7 files changed

+136
-56
lines changed

benchmark/single-source/AnyHashableWithAClass.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
// upcast the instance to the type that introduces the Hashable
1515
// conformance.
1616

17+
import TestsUtils
18+
19+
// 23% _swift_dynamicCast
20+
// 23% _swift_release_
21+
// 18% _swift_stdlib_makeAnyHashableUsingDefaultRepresentation
22+
// 11% _swift_stdlib_makeAnyHashableUpcastingToHashableBaseType
23+
// 16% _swift_retain_[n]
24+
// 5% swift_conformsToProtocol
25+
public var AnyHashableWithAClass = BenchmarkInfo(
26+
name: "AnyHashableWithAClass",
27+
runFunction: run_AnyHashableWithAClass,
28+
tags: [.abstraction, .runtime, .cpubench]
29+
)
30+
1731
class TestHashableBase : Hashable {
1832
var value: Int
1933
init(_ value: Int) {

benchmark/single-source/Exclusivity.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@
1717

1818
import TestsUtils
1919

20+
// At -Onone
21+
// 25% swift_beginAccess
22+
// 15% tlv_get_addr
23+
// 15% swift_endAccess
24+
public var ExclusivityGlobal = BenchmarkInfo(
25+
name: "ExclusivityGlobal",
26+
runFunction: run_accessGlobal,
27+
tags: [.runtime, .cpubench]
28+
)
29+
// At -Onone
30+
// 23% swift_retain
31+
// 22% swift_release
32+
// 9% swift_beginAccess
33+
// 3% swift_endAccess
34+
public var ExclusivityInMatSet = BenchmarkInfo(
35+
name: "ExclusivityInMatSet",
36+
runFunction: run_accessInMatSet,
37+
tags: [.runtime, .cpubench]
38+
)
39+
// At -Onone
40+
// 25% swift_release
41+
// 23% swift_retain
42+
// 16% swift_beginAccess
43+
// 8% swift_endAccess
44+
public var ExclusivityIndependent = BenchmarkInfo(
45+
name: "ExclusivityIndependent",
46+
runFunction: run_accessIndependent,
47+
tags: [.runtime, .cpubench]
48+
)
49+
2050
// Initially these benchmarks only measure access checks at -Onone. In
2151
// the future, access checks will also be emitted at -O.
2252

benchmark/single-source/LinkedList.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
// utils/benchmark, with modifications for performance measuring.
1515
import TestsUtils
1616

17+
// 47% _swift_retain
18+
// 43% _swift_release
19+
public var LinkedList = BenchmarkInfo(
20+
name: "LinkedList",
21+
runFunction: run_LinkedList,
22+
tags: [.runtime, .cpubench, .refcount]
23+
)
24+
1725
final class Node {
1826
var next: Node?
1927
var data: Int

benchmark/single-source/PolymorphicCalls.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ applying a jump-threading in combination with the speculative devirtualization.
2222

2323
import TestsUtils
2424

25+
public var PolymorphicCalls = BenchmarkInfo(
26+
name: "PolymorphicCalls",
27+
runFunction: run_PolymorphicCalls,
28+
tags: [.abstraction, .cpubench]
29+
)
30+
2531
public class A {
2632
let b: B
2733
init(b:B) {

benchmark/single-source/SevenBoom.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
import TestsUtils
1414
import Foundation
1515

16+
// 15% _swift_allocObject (String.bridgeToObjectiveC)
17+
// 14% [NSError dealloc]
18+
// 14% objc_allocWithZone
19+
// 10% _swift_allocObject
20+
// 11% _swift_release_dealloc
21+
// 8% objc_release
22+
// 7% objc_msgSend
23+
// 5% _swift_release_
24+
// 2% _swift_retain_
25+
public var SevenBoom = BenchmarkInfo(
26+
name: "SevenBoom",
27+
runFunction: run_SevenBoom,
28+
tags: [.runtime, .exceptions, .bridging, .cpubench]
29+
)
30+
1631
@inline(never)
1732
func filter_seven(_ input : Int) throws {
1833
guard case 7 = input else {

benchmark/utils/TestsUtils.swift

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,54 @@ import Darwin
1717
#endif
1818

1919
public enum BenchmarkCategories : CustomStringConvertible {
20-
// Validation "micro" benchmarks test a specific operation or critical path that
21-
// we know is important to measure.
22-
case validation
23-
// subsystems to validate and their subcategories.
24-
case api, Array, String, Dictionary, Codable, Set
25-
case sdk
26-
case runtime, refcount, metadata
27-
// Other general areas of compiled code validation.
28-
case abstraction, safetychecks, exceptions, bridging, concurrency
29-
30-
// Algorithms are "micro" that test some well-known algorithm in isolation:
31-
// sorting, searching, hashing, fibonaci, crypto, etc.
32-
case algorithm
33-
34-
// Miniapplications are contrived to mimic some subset of application behavior
35-
// in a way that can be easily measured. They are larger than micro-benchmarks,
36-
// combining multiple APIs, data structures, or algorithms. This includes small
37-
// standardized benchmarks, pieces of real applications that have been extracted
38-
// into a benchmark, important functionality like JSON parsing, etc.
39-
case miniapplication
40-
41-
// Regression benchmarks is a catch-all for less important "micro"
42-
// benchmarks. This could be a random piece of code that was attached to a bug
43-
// report. We want to make sure the optimizer as a whole continues to handle
44-
// this case, but don't know how applicable it is to general Swift performance
45-
// relative to the other micro-benchmarks. In particular, these aren't weighted
46-
// as highly as "validation" benchmarks and likely won't be the subject of
47-
// future investigation unless they significantly regress.
48-
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
20+
// Validation "micro" benchmarks test a specific operation or critical path that
21+
// we know is important to measure.
22+
case validation
23+
// subsystems to validate and their subcategories.
24+
case api, Array, String, Dictionary, Codable, Set
25+
case sdk
26+
case runtime, refcount, metadata
27+
// Other general areas of compiled code validation.
28+
case abstraction, safetychecks, exceptions, bridging, concurrency
29+
30+
// Algorithms are "micro" that test some well-known algorithm in isolation:
31+
// sorting, searching, hashing, fibonaci, crypto, etc.
32+
case algorithm
33+
34+
// Miniapplications are contrived to mimic some subset of application behavior
35+
// in a way that can be easily measured. They are larger than micro-benchmarks,
36+
// combining multiple APIs, data structures, or algorithms. This includes small
37+
// standardized benchmarks, pieces of real applications that have been extracted
38+
// into a benchmark, important functionality like JSON parsing, etc.
39+
case miniapplication
40+
41+
// Regression benchmarks is a catch-all for less important "micro"
42+
// benchmarks. This could be a random piece of code that was attached to a bug
43+
// report. We want to make sure the optimizer as a whole continues to handle
44+
// this case, but don't know how applicable it is to general Swift performance
45+
// relative to the other micro-benchmarks. In particular, these aren't weighted
46+
// as highly as "validation" benchmarks and likely won't be the subject of
47+
// future investigation unless they significantly regress.
48+
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
6868

6969
public var description : String {
7070
switch self {

benchmark/utils/main.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ import UTF8Decode
124124
import Walsh
125125
import XorLoop
126126

127+
@inline(__always)
128+
private func registerBenchmark(_ bench: BenchmarkInfo) {
129+
registeredBenchmarks.append(bench)
130+
}
131+
132+
registerBenchmark(AnyHashableWithAClass)
133+
registerBenchmark(ArraySetElement)
134+
registerBenchmark(ExclusivityGlobal)
135+
registerBenchmark(ExclusivityInMatSet)
136+
registerBenchmark(ExclusivityIndependent)
137+
registerBenchmark(LinkedList)
138+
registerBenchmark(ObjectAllocation)
139+
registerBenchmark(PolymorphicCalls)
140+
registerBenchmark(SevenBoom)
141+
127142
@inline(__always)
128143
private func addTo(
129144
_ testSuite: inout [String : ((Int) -> (), [BenchmarkCategories])],
@@ -134,14 +149,6 @@ private func addTo(
134149
testSuite[name] = (function, tags)
135150
}
136151

137-
@inline(__always)
138-
private func registerBenchmark(_ bench: BenchmarkInfo) {
139-
registeredBenchmarks.append(bench)
140-
}
141-
142-
registerBenchmark(ArraySetElement)
143-
registerBenchmark(ObjectAllocation)
144-
145152
// The main test suite: precommit tests
146153
addTo(&precommitTests, "AngryPhonebook", run_AngryPhonebook, [.validation, .api, .String])
147154
addTo(&precommitTests, "AnyHashableWithAClass", run_AnyHashableWithAClass, [.validation, .abstraction, .runtime])

0 commit comments

Comments
 (0)