@@ -3,140 +3,139 @@ package benchmarks
3
3
import scala .quoted ._
4
4
import scala .quoted .staging ._
5
5
import strymonas ._
6
+ import strymonas .Code .given
6
7
7
8
object TestPipelines {
8
9
given Compiler = Compiler .make(getClass.getClassLoader)
9
- import Settings ._
10
-
11
- import strymonas .Code ._
12
- import strymonas .Code .given
13
- import scala .language .implicitConversions
10
+ given Raw = Raw (Code )
14
11
15
12
def sumPipeline (using Quotes ) = ' { (array : Array [Long ]) =>
16
13
$ { Cooked .of(' {array})
17
- .fold(long( 0 ) , _+_) }
14
+ .fold(0L , _+_) }
18
15
}
19
16
20
17
def sumOfSquaresPipeline (using Quotes ) = ' { (array : Array [Long ]) =>
21
18
$ { Cooked .of(' {array})
22
- .map((a) => a * a)
23
- .fold(long( 0 ) , _+_) }
19
+ .map(a => a * a)
20
+ .fold(0L , _+_) }
24
21
}
25
22
26
23
def sumOfSquaresEvenPipeline (using Quotes ) = ' { (array : Array [Long ]) =>
27
24
$ { Cooked .of(' {array})
28
- .filter(d => (d mod long( 2 )) === long( 0 ) )
29
- .map((a) => a * a )
30
- .fold(long( 0 ) , _+_) }
25
+ .filter(d => (d mod 2L ) === 0L )
26
+ .map(a => a * a )
27
+ .fold(0L , _+_) }
31
28
}
32
29
33
30
def cartPipeline (using Quotes ) = ' { (vHi : Array [Long ], vLo : Array [Long ]) =>
34
31
$ { Cooked .of(' {vHi})
35
- .flatMap((d) => Cooked .of(' {vLo}).map((dp) => d * dp))
36
- .fold(long( 0 ) , _+_) }
32
+ .flatMap(d => Cooked .of(' {vLo}).map(dp => d * dp))
33
+ .fold(0L , _+_) }
37
34
}
38
35
39
36
def mapsMegamorphicPipeline (using Quotes ) = ' { (array : Array [Long ]) =>
40
37
$ { Cooked .of(' {array})
41
- .map((a) => a * long( 1 ) )
42
- .map((a) => a * long( 2 ) )
43
- .map((a) => a * long( 3 ) )
44
- .map((a) => a * long( 4 ) )
45
- .map((a) => a * long( 5 ) )
46
- .map((a) => a * long( 6 ) )
47
- .map((a) => a * long( 7 ) )
48
- .fold(long( 0 ) , _+_) }
38
+ .map(a => a * 1L )
39
+ .map(a => a * 2L )
40
+ .map(a => a * 3L )
41
+ .map(a => a * 4L )
42
+ .map(a => a * 5L )
43
+ .map(a => a * 6L )
44
+ .map(a => a * 7L )
45
+ .fold(0L , _+_) }
49
46
}
50
47
51
48
def filtersMegamorphicPipeline (using Quotes ) = ' { (array : Array [Long ]) =>
52
49
$ { Cooked .of(' {array})
53
- .filter((a) => a > long( 1 ) )
54
- .filter((a) => a > long( 2 ) )
55
- .filter((a) => a > long( 3 ) )
56
- .filter((a) => a > long( 4 ) )
57
- .filter((a) => a > long( 5 ) )
58
- .filter((a) => a > long( 6 ) )
59
- .filter((a) => a > long( 7 ) )
60
- .fold(long( 0 ) , _+_) }
50
+ .filter(a => a > 1L )
51
+ .filter(a => a > 2L )
52
+ .filter(a => a > 3L )
53
+ .filter(a => a > 4L )
54
+ .filter(a => a > 5L )
55
+ .filter(a => a > 6L )
56
+ .filter(a => a > 7L )
57
+ .fold(0L , _+_) }
61
58
}
62
59
63
60
def filterPipeline (using Quotes ) = ' { (array : Array [Long ]) =>
64
61
$ { Cooked .of(' {array})
65
- .filter(d => (d mod long( 2 )) === long( 0 ) )
66
- .fold(long( 0 ) , _+_) }
62
+ .filter(d => (d mod 2L ) === 0L )
63
+ .fold(0L , _+_) }
67
64
}
68
65
69
66
def takePipeline (using Quotes ) = ' { (array : Array [Long ]) =>
70
67
$ { Cooked .of(' {array})
71
- .take(int( 2 ) )
72
- .fold(long( 0 ) , _+_) }
68
+ .take(2 )
69
+ .fold(0L , _+_) }
73
70
}
74
71
75
72
def flatMapTakePipeline (using Quotes ) = ' { (array1 : Array [Long ], array2 : Array [Long ]) =>
76
73
$ { Cooked .of(' {array1})
77
- .flatMap((d) => Cooked .of(' {array2}).map(y => y * d))
78
- .take(int( vLimit_s) )
79
- .fold(long( 0 ) , _+_) }
74
+ .flatMap(d => Cooked .of(' {array2}).map(y => y * d))
75
+ .take(Settings . vLimit_s)
76
+ .fold(0L , _+_) }
80
77
}
81
78
82
79
def dotProductPipeline (using Quotes ) = ' { (array1 : Array [Long ], array2 : Array [Long ]) =>
83
80
$ { Cooked .of(' {array1})
84
- .zipWith[ Long , Long ] (Cooked .of(' {array2}), _* _)
85
- .fold(long( 0 ) , _+_) }
81
+ .zipWith(Cooked .of(' {array2}), _* _)
82
+ .fold(0L , _+_) }
86
83
}
87
84
88
85
def flatMapAfterZipPipeline (using Quotes ) = ' { (array1 : Array [Long ], array2 : Array [Long ]) =>
89
86
$ { Cooked .of(' {array1})
90
- .zipWith[ Long , Long ] (Cooked .of(' {array1}), _+_)
91
- .flatMap((d) => Cooked .of(' {array2}).map((dp) => d + dp))
92
- .fold(long( 0 ) , _+_) }
87
+ .zipWith(Cooked .of(' {array1}), _+_)
88
+ .flatMap(d => Cooked .of(' {array2}).map(dp => d + dp))
89
+ .fold(0L , _+_) }
93
90
}
94
91
95
92
def zipAfterFlatMapPipeline (using Quotes ) = ' { (array1 : Array [Long ], array2 : Array [Long ]) =>
96
93
$ { Cooked .of(' {array1})
97
- .flatMap((d) => Cooked .of(' {array2}).map((dp) => d + dp))
98
- .zipWith[ Long , Long ] (Cooked .of(' {array1}), _+_)
99
- .fold(long( 0 ) , _+_) }
94
+ .flatMap(d => Cooked .of(' {array2}).map(dp => d + dp))
95
+ .zipWith(Cooked .of(' {array1}), _+_)
96
+ .fold(0L , _+_) }
100
97
}
101
98
102
99
def zipFlatMapFlatMapPipeline (using Quotes ) = ' { (array1 : Array [Long ], array2 : Array [Long ]) =>
103
100
$ { Cooked .of(' {array1})
104
- .flatMap((d) => Cooked .of(' {array2}).map((dp) => d * dp))
105
- .zipWith[ Long , Long ] (Cooked .of(' {array2}).flatMap((d) => Cooked .of(' {array1}).map((dp) => d - dp)), _+_)
106
- .take(int( vLimit_s) )
107
- .fold(long( 0 ) , _+_) }
101
+ .flatMap(d => Cooked .of(' {array2}).map(dp => d * dp))
102
+ .zipWith(Cooked .of(' {array2}).flatMap(d => Cooked .of(' {array1}).map(dp => d - dp)), _+_)
103
+ .take(Settings . vLimit_s)
104
+ .fold(0L , _+_) }
108
105
}
109
106
110
107
def zipFilterFilterPipeline (using Quotes ) = ' { (array1 : Array [Long ], array2 : Array [Long ]) =>
111
- $ { Cooked .of(' {array1}).filter((d) => d > long( 7 ) )
112
- .zipWith[ Long , Long ] (Cooked .of(' {array2}).filter((d) => d > long( 5 ) ), _+_)
113
- .fold(long( 0 ) , _+_) }
108
+ $ { Cooked .of(' {array1}).filter(d => d > 7L )
109
+ .zipWith(Cooked .of(' {array2}).filter(d => d > 5L ), _+_)
110
+ .fold(0L , _+_) }
114
111
}
115
112
116
113
extension (st : Cooked [Long ])
114
+
117
115
def decode ()(using Quotes ): Cooked [Boolean ] =
118
- st
119
- .map(e => toInt(e))
120
- .flatMap {el =>
121
- def newShape ( using raw : Raw ) =
122
- import raw . _
123
- import raw . code ._
124
- import raw . code . given
125
- mkPullArray[ Cde [ Boolean ]](el, i => k =>
126
- if_(i < el ,
127
- k(bool(false )),
128
- if1(i < int( 255 ), k(bool( true )) )
116
+ import strymonas . Code . _
117
+
118
+ st.map(e => toInt(e))
119
+ .flatMap {el =>
120
+ def newShape ( using raw : Raw ) =
121
+ import raw ._
122
+ mkPullArray[ Cde [ Boolean ]](el, i => k =>
123
+ if_(i < el,
124
+ k(bool( false )) ,
125
+ if1(i < int( 255 ), k(bool(true )))
126
+ )
129
127
)
130
- )
131
-
132
- Cooked (st.raw, newShape)
133
- }
128
+
129
+ Cooked (newShape)
130
+ }
134
131
135
132
def decodingPipeline (using Quotes ) = ' { (array1 : Array [Long ], array2 : Array [Long ]) =>
133
+ import strymonas .Code ._
134
+
136
135
$ { Cooked .of(' {array1})
137
- .decode()
138
- .zipWith[Boolean , Boolean ](Cooked .of(' {array2}).decode(), _|| _)
139
- .map(x => cond(x, long( 1 ), long( 0 ) ))
140
- .fold(long( 0 ) , _+_) }
136
+ .decode()
137
+ .zipWith[Boolean , Boolean ](Cooked .of(' {array2}).decode(), _|| _)
138
+ .map(x => cond(x, 1L , 0L ))
139
+ .fold(0L , _+_) }
141
140
}
142
141
}
0 commit comments