@@ -18,8 +18,12 @@ public let MapReduce = [
18
18
BenchmarkInfo ( name: " MapReduceAnyCollection " , runFunction: run_MapReduceAnyCollection, tags: [ . validation, . algorithm] ) ,
19
19
BenchmarkInfo ( name: " MapReduceAnyCollectionShort " , runFunction: run_MapReduceAnyCollectionShort, tags: [ . validation, . algorithm] ) ,
20
20
BenchmarkInfo ( name: " MapReduceClass2 " , runFunction: run_MapReduceClass, tags: [ . validation, . algorithm] ,
21
- setUpFunction: { decimals ( 1000 ) } , tearDownFunction: releaseDecimals) ,
21
+ setUpFunction: { boxedNumbers ( 1000 ) } , tearDownFunction: releaseDecimals) ,
22
22
BenchmarkInfo ( name: " MapReduceClassShort2 " , runFunction: run_MapReduceClassShort, tags: [ . validation, . algorithm] ,
23
+ setUpFunction: { boxedNumbers ( 10 ) } , tearDownFunction: releaseDecimals) ,
24
+ BenchmarkInfo ( name: " MapReduceNSDecimalNumber " , runFunction: run_MapReduceNSDecimalNumber, tags: [ . validation, . algorithm] ,
25
+ setUpFunction: { decimals ( 1000 ) } , tearDownFunction: releaseDecimals) ,
26
+ BenchmarkInfo ( name: " MapReduceNSDecimalNumberShort " , runFunction: run_MapReduceNSDecimalNumberShort, tags: [ . validation, . algorithm] ,
23
27
setUpFunction: { decimals ( 10 ) } , tearDownFunction: releaseDecimals) ,
24
28
BenchmarkInfo ( name: " MapReduceLazyCollection " , runFunction: run_MapReduceLazyCollection, tags: [ . validation, . algorithm] ) ,
25
29
BenchmarkInfo ( name: " MapReduceLazyCollectionShort " , runFunction: run_MapReduceLazyCollectionShort, tags: [ . validation, . algorithm] ) ,
@@ -41,6 +45,15 @@ func decimals(_ n: Int) {}
41
45
func releaseDecimals( ) { }
42
46
#endif
43
47
48
+ class Box {
49
+ var v : Int
50
+ init ( _ v: Int ) { self . v = v }
51
+ }
52
+
53
+ var boxedNumbers : [ Box ] !
54
+ func boxedNumbers( _ n: Int ) { boxedNumbers = ( 0 ..< n) . map { Box ( $0) } }
55
+ func releaseboxedNumbers( ) { boxedNumbers = nil }
56
+
44
57
@inline ( never)
45
58
public func run_MapReduce( _ N: Int ) {
46
59
var numbers = [ Int] ( 0 ..< 1000 )
@@ -160,12 +173,12 @@ public func run_MapReduceShortString(_ N: Int) {
160
173
}
161
174
162
175
@inline ( never)
163
- public func run_MapReduceClass ( _ N: Int ) {
176
+ public func run_MapReduceNSDecimalNumber ( _ N: Int ) {
164
177
#if _runtime(_ObjC)
165
178
let numbers : [ NSDecimalNumber ] = decimals
166
179
167
180
var c = 0
168
- for _ in 1 ... N*100 {
181
+ for _ in 1 ... N*10 {
169
182
let mapped = numbers. map { $0. intValue &+ 5 }
170
183
c += mapped. reduce ( 0 , &+ )
171
184
}
@@ -174,15 +187,40 @@ public func run_MapReduceClass(_ N: Int) {
174
187
}
175
188
176
189
@inline ( never)
177
- public func run_MapReduceClassShort ( _ N: Int ) {
190
+ public func run_MapReduceNSDecimalNumberShort ( _ N: Int ) {
178
191
#if _runtime(_ObjC)
179
192
let numbers : [ NSDecimalNumber ] = decimals
180
193
181
194
var c = 0
182
- for _ in 1 ... N*10000 {
195
+ for _ in 1 ... N*1_000 {
183
196
let mapped = numbers. map { $0. intValue &+ 5 }
184
197
c += mapped. reduce ( 0 , &+ )
185
198
}
186
199
CheckResults ( c != 0 )
187
200
#endif
188
201
}
202
+
203
+
204
+ @inline ( never)
205
+ public func run_MapReduceClass( _ N: Int ) {
206
+ let numbers : [ Box ] = boxedNumbers
207
+
208
+ var c = 0
209
+ for _ in 1 ... N*10 {
210
+ let mapped = numbers. map { $0. v &+ 5 }
211
+ c += mapped. reduce ( 0 , &+ )
212
+ }
213
+ CheckResults ( c != 0 )
214
+ }
215
+
216
+ @inline ( never)
217
+ public func run_MapReduceClassShort( _ N: Int ) {
218
+ let numbers : [ Box ] = boxedNumbers
219
+
220
+ var c = 0
221
+ for _ in 1 ... N*1_000 {
222
+ let mapped = numbers. map { $0. v &+ 5 }
223
+ c += mapped. reduce ( 0 , &+ )
224
+ }
225
+ CheckResults ( c != 0 )
226
+ }
0 commit comments