@@ -39,10 +39,7 @@ public let benchmarks = [
39
39
]
40
40
41
41
// Number of iterations for each benchmark.
42
- let numberOfIterationsForNestedStructs = 20000
43
- let numberOfIterationsForDirectAccess = 1_000_000
44
- let numberOfIterationsForKeyPathReadPerformance = 2000
45
- let numberOfIterationsForKeyPathWritePerformance = 12000
42
+ let numberOfElementsForNestedStructs = 20000
46
43
47
44
// Make it easy to switch between primitives of different types (Int, Float, Double, etc.).
48
45
typealias ElementType = Double
@@ -78,7 +75,7 @@ class FixedSizeArrayHolder {
78
75
// Setup Functions.
79
76
public func setupKeyPathNestedStructs( ) {
80
77
FixedSizeArrayHolder . shared. forceInstantiation ( )
81
- for _ in 0 ..< numberOfIterationsForNestedStructs {
78
+ for _ in 0 ..< numberOfElementsForNestedStructs {
82
79
let instance = A ( a: 0 , b: B ( b: 0 , c: C ( c: 0 , d: D ( d: 0 , e: E ( e: expectedIntForNestedStructs) ) ) ) )
83
80
FixedSizeArrayHolder . shared. mainArrayForNestedStructs. append ( instance)
84
81
}
@@ -884,21 +881,26 @@ func returnKeyPathArray() -> [AnyKeyPath] {
884
881
}
885
882
886
883
@inline ( never)
887
- public func run_KeyPathNestedStructs( n _ : Int ) {
884
+ public func run_KeyPathNestedStructs( n: Int ) {
888
885
var sum = 0
889
- for el in FixedSizeArrayHolder . shared. mainArrayForNestedStructs {
890
- sum += el [ keyPath: appendedKeyPath]
886
+ var index = 0
887
+ let iterationMultipier = 200
888
+ for _ in 1 ... iterationMultipier * n {
889
+ let element = FixedSizeArrayHolder . shared. mainArrayForNestedStructs [ index]
890
+ sum += element [ keyPath: appendedKeyPath]
891
+ index = ( index + 1 ) % FixedSizeArrayHolder. shared. mainArrayForNestedStructs. count
891
892
}
892
- assert ( sum == numberOfIterationsForNestedStructs * expectedIntForNestedStructs)
893
+ assert ( sum == iterationMultipier * n * expectedIntForNestedStructs)
893
894
}
894
895
895
896
// This is meant as a baseline, from a timing perspective,
896
897
// for run_testKeyPathReadPerformance() and run_testKeyPathWritePerformance().
897
898
@inline ( never)
898
- public func run_testDirectAccess( n _ : Int ) {
899
+ public func run_testDirectAccess( n: Int ) {
899
900
arrayHolder. reset ( )
900
901
var fixedSizeArray100 = FixedSizeArrayHolder . shared. fixedSizeArray100
901
- for t in 0 ..< numberOfIterationsForDirectAccess {
902
+ let iterationMultipier = 3000
903
+ for t in 1 ... iterationMultipier * n {
902
904
fixedSizeArray100. element50 += fixedSizeArray100. element1 + ElementType( t)
903
905
fixedSizeArray100. element46 += fixedSizeArray100. element63 - fixedSizeArray100. element99
904
906
fixedSizeArray100. element43 += fixedSizeArray100. element39 * fixedSizeArray100. element27
@@ -932,10 +934,11 @@ public func run_testDirectAccess(n _: Int) {
932
934
933
935
// This measures read performance of keypaths.
934
936
@inline ( never)
935
- public func run_testKeyPathReadPerformance( n _ : Int ) {
937
+ public func run_testKeyPathReadPerformance( n: Int ) {
936
938
arrayHolder. reset ( )
937
939
var fixedSizeArray100 = FixedSizeArrayHolder . shared. fixedSizeArray100
938
- for t in 0 ..< numberOfIterationsForKeyPathReadPerformance {
940
+ let iterationMultipier = 25
941
+ for t in 1 ... iterationMultipier * n {
939
942
fixedSizeArray100. element50 += fixedSizeArray100. element1 + ElementType( t)
940
943
fixedSizeArray100. element46 += fixedSizeArray100. element63 - fixedSizeArray100[ keyPath: kp99]
941
944
fixedSizeArray100. element43 += fixedSizeArray100. element39 * fixedSizeArray100[ keyPath: kp27]
@@ -969,10 +972,11 @@ public func run_testKeyPathReadPerformance(n _: Int) {
969
972
970
973
// This measures write performance of keypaths.
971
974
@inline ( never)
972
- public func run_testKeyPathWritePerformance( n _ : Int ) {
975
+ public func run_testKeyPathWritePerformance( n: Int ) {
973
976
arrayHolder. reset ( )
974
977
var fixedSizeArray100 = FixedSizeArrayHolder . shared. fixedSizeArray100
975
- for t in 0 ..< numberOfIterationsForKeyPathWritePerformance {
978
+ let iterationMultipier = 150
979
+ for t in 1 ... iterationMultipier * n {
976
980
fixedSizeArray100. element50 += fixedSizeArray100. element1 + ElementType( t)
977
981
fixedSizeArray100 [ keyPath: kp46] += fixedSizeArray100. element63 - fixedSizeArray100. element99
978
982
fixedSizeArray100 [ keyPath: kp43] += fixedSizeArray100. element39 * fixedSizeArray100. element27
0 commit comments