File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ set(SWIFT_BENCH_MODULES
21
21
single-source/unit-tests/StackPromo
22
22
single-source/Ackermann
23
23
single-source/AngryPhonebook
24
+ single-source/AnyHashableWithAClass
24
25
single-source/Array2D
25
26
single-source/ArrayAppend
26
27
single-source/ArrayInClass
Original file line number Diff line number Diff line change
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See http://swift.org/LICENSE.txt for license information
9
+ // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ // This benchmark tests AnyHashable's initializer that needs to dynamically
14
+ // upcast the instance to the type that introduces the Hashable
15
+ // conformance.
16
+
17
+ class TestHashableBase : Hashable {
18
+ var value : Int
19
+ init ( _ value: Int ) {
20
+ self . value = value
21
+ }
22
+ var hashValue : Int {
23
+ return value
24
+ }
25
+ static func == (
26
+ lhs: TestHashableBase ,
27
+ rhs: TestHashableBase
28
+ ) -> Bool {
29
+ return lhs. value == rhs. value
30
+ }
31
+ }
32
+
33
+ class TestHashableDerived1 : TestHashableBase { }
34
+ class TestHashableDerived2 : TestHashableDerived1 { }
35
+ class TestHashableDerived3 : TestHashableDerived2 { }
36
+ class TestHashableDerived4 : TestHashableDerived3 { }
37
+ class TestHashableDerived5 : TestHashableDerived4 { }
38
+
39
+ @inline ( never)
40
+ public func run_AnyHashableWithAClass( _ N: Int ) {
41
+ let c = TestHashableDerived5 ( 10 )
42
+ for _ in 0 ... ( N*500000) {
43
+ _ = AnyHashable ( c)
44
+ }
45
+ }
46
+
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import TestsUtils
22
22
import DriverUtils
23
23
import Ackermann
24
24
import AngryPhonebook
25
+ import AnyHashableWithAClass
25
26
import Array2D
26
27
import ArrayAppend
27
28
import ArrayInClass
@@ -100,6 +101,7 @@ import XorLoop
100
101
101
102
precommitTests = [
102
103
" AngryPhonebook " : run_AngryPhonebook,
104
+ " AnyHashableWithAClass " : run_AnyHashableWithAClass,
103
105
" Array2D " : run_Array2D,
104
106
" ArrayAppend " : run_ArrayAppend,
105
107
" ArrayAppendReserved " : run_ArrayAppendReserved,
You can’t perform that action at this time.
0 commit comments