@@ -19,9 +19,139 @@ public func run_MapReduce(_ N: Int) {
19
19
20
20
var c = 0
21
21
for _ in 1 ... N*100 {
22
- numbers = numbers. map ( { $0 &+ 5 } )
22
+ numbers = numbers. map { $0 &+ 5 }
23
23
c += numbers. reduce ( 0 , &+ )
24
24
}
25
25
CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
26
26
}
27
27
28
+ @inline ( never)
29
+ public func run_MapReduceAnyCollection( _ N: Int ) {
30
+ let numbers = AnyCollection ( [ Int] ( 0 ..< 1000 ) )
31
+
32
+ var c = 0
33
+ for _ in 1 ... N*100 {
34
+ let mapped = numbers. map { $0 &+ 5 }
35
+ c += mapped. reduce ( 0 , &+ )
36
+ }
37
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
38
+ }
39
+
40
+ @inline ( never)
41
+ public func run_MapReduceAnyCollectionShort( _ N: Int ) {
42
+ let numbers = AnyCollection ( [ Int] ( 0 ..< 10 ) )
43
+
44
+ var c = 0
45
+ for _ in 1 ... N*10000 {
46
+ let mapped = numbers. map { $0 &+ 5 }
47
+ c += mapped. reduce ( 0 , &+ )
48
+ }
49
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
50
+ }
51
+
52
+ @inline ( never)
53
+ public func run_MapReduceShort( _ N: Int ) {
54
+ var numbers = [ Int] ( 0 ..< 10 )
55
+
56
+ var c = 0
57
+ for _ in 1 ... N*10000 {
58
+ numbers = numbers. map { $0 &+ 5 }
59
+ c += numbers. reduce ( 0 , &+ )
60
+ }
61
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
62
+ }
63
+
64
+ @inline ( never)
65
+ public func run_MapReduceSequence( _ N: Int ) {
66
+ let numbers = sequence ( first: 0 ) { $0 < 1000 ? $0 &+ 1 : nil }
67
+
68
+ var c = 0
69
+ for _ in 1 ... N*100 {
70
+ let mapped = numbers. map { $0 &+ 5 }
71
+ c += mapped. reduce ( 0 , &+ )
72
+ }
73
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
74
+ }
75
+
76
+ @inline ( never)
77
+ public func run_MapReduceLazySequence( _ N: Int ) {
78
+ let numbers = sequence ( first: 0 ) { $0 < 1000 ? $0 &+ 1 : nil }
79
+
80
+ var c = 0
81
+ for _ in 1 ... N*100 {
82
+ let mapped = numbers. lazy. map { $0 &+ 5 }
83
+ c += mapped. reduce ( 0 , &+ )
84
+ }
85
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
86
+ }
87
+
88
+ @inline ( never)
89
+ public func run_MapReduceLazyCollection( _ N: Int ) {
90
+ let numbers = [ Int] ( 0 ..< 1000 )
91
+
92
+ var c = 0
93
+ for _ in 1 ... N*100 {
94
+ let mapped = numbers. lazy. map { $0 &+ 5 }
95
+ c += mapped. reduce ( 0 , &+ )
96
+ }
97
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
98
+ }
99
+
100
+ @inline ( never)
101
+ public func run_MapReduceLazyCollectionShort( _ N: Int ) {
102
+ let numbers = [ Int] ( 0 ..< 10 )
103
+
104
+ var c = 0
105
+ for _ in 1 ... N*10000 {
106
+ let mapped = numbers. lazy. map { $0 &+ 5 }
107
+ c += mapped. reduce ( 0 , &+ )
108
+ }
109
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
110
+ }
111
+
112
+ @inline ( never)
113
+ public func run_MapReduceString( _ N: Int ) {
114
+ let s = " thequickbrownfoxjumpsoverthelazydogusingasmanycharacteraspossible123456789 "
115
+
116
+ var c : UInt64 = 0
117
+ for _ in 1 ... N*100 {
118
+ c += s. utf8. map { UInt64 ( $0 &+ 5 ) } . reduce ( 0 , &+ )
119
+ }
120
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
121
+ }
122
+
123
+ @inline ( never)
124
+ public func run_MapReduceShortString( _ N: Int ) {
125
+ let s = " 12345 "
126
+
127
+ var c : UInt64 = 0
128
+ for _ in 1 ... N*100 {
129
+ c += s. utf8. map { UInt64 ( $0 &+ 5 ) } . reduce ( 0 , &+ )
130
+ }
131
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
132
+ }
133
+
134
+ @inline ( never)
135
+ public func run_MapReduceClass( _ N: Int ) {
136
+ let numbers = ( 0 ..< 1000 ) . map { NSDecimalNumber ( value: $0) }
137
+
138
+ var c = 0
139
+ for _ in 1 ... N*100 {
140
+ let mapped = numbers. map { $0. intValue &+ 5 }
141
+ c += mapped. reduce ( 0 , &+ )
142
+ }
143
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
144
+ }
145
+
146
+ @inline ( never)
147
+ public func run_MapReduceClassShort( _ N: Int ) {
148
+ let numbers = ( 0 ..< 10 ) . map { NSDecimalNumber ( value: $0) }
149
+
150
+ var c = 0
151
+ for _ in 1 ... N*10000 {
152
+ let mapped = numbers. map { $0. intValue &+ 5 }
153
+ c += mapped. reduce ( 0 , &+ )
154
+ }
155
+ CheckResults ( c != 0 , " IncorrectResults in MapReduce " )
156
+ }
157
+
0 commit comments