@@ -5,10 +5,8 @@ module Main (main) where
5
5
6
6
import Control.DeepSeq
7
7
import Control.Exception (evaluate )
8
- import Control.Monad
9
8
import Control.Monad.ST
10
- import Criterion.Main
11
- import Criterion.Types
9
+ import Data.Maybe
12
10
import qualified Data.List as L
13
11
import qualified Data.DList as D
14
12
import qualified Data.Sequence as S
@@ -20,8 +18,12 @@ import qualified Data.Massiv.Array as M
20
18
import qualified Data.RRBVector as RRB
21
19
import qualified Acc
22
20
import qualified GHC.Exts
23
- import System.Directory
21
+ import System.Exit
24
22
import System.Random
23
+ import Test.Tasty.Bench
24
+ import Test.Tasty.Ingredients
25
+ import Test.Tasty.Options
26
+ import Test.Tasty.Runners
25
27
26
28
data Conser = forall f . NFData (f Int ) => Conser String (Int -> IO (f Int )) (Int -> f Int -> f Int )
27
29
data Snocer = forall f . NFData (f Int ) => Snocer String (Int -> IO (f Int )) (f Int -> Int -> f Int )
@@ -37,12 +39,14 @@ data RemoveByIndex = forall f. NFData (f Int) => RemoveByIndex String (IO (f Int
37
39
38
40
main :: IO ()
39
41
main = do
40
- let fp = " out.csv"
41
- exists <- doesFileExist fp
42
- when exists (removeFile fp)
43
- defaultMainWith
44
- defaultConfig {csvFile = Just fp}
45
- [ bgroup
42
+ opts <- parseOptions benchIngredients benchmarks
43
+ let opts' = changeOption (Just . fromMaybe (CsvPath " out.csv" )) opts
44
+ case tryIngredients benchIngredients opts' benchmarks of
45
+ Nothing -> exitFailure
46
+ Just mb -> mb >>= \ b -> if b then exitSuccess else exitFailure
47
+ where
48
+ benchmarks = bgroup " All"
49
+ [ bgroup
46
50
" Consing"
47
51
(conses
48
52
[ Conser " Data.List" sampleList (:)
@@ -54,7 +58,7 @@ main = do
54
58
, Conser " Data.RRBVector" sampleRRB (RRB. <|)
55
59
, Conser " Data.Acc" sampleAcc Acc. cons
56
60
])
57
- , bgroup
61
+ , bgroup
58
62
" Snocing"
59
63
(snocs
60
64
[ Snocer " Data.DList" sampleDList D. snoc
@@ -65,7 +69,7 @@ main = do
65
69
, Snocer " Data.RRBVector" sampleRRB (RRB. |>)
66
70
, Snocer " Data.Acc" sampleAcc (flip Acc. snoc)
67
71
])
68
- , bgroup
72
+ , bgroup
69
73
" Indexing"
70
74
(let size = 10005
71
75
in indexes
@@ -77,7 +81,7 @@ main = do
77
81
, Indexing " Data.Massiv.Array" (sampleMassivUArray size) M. index'
78
82
, Indexing " Data.RRBVector" (sampleRRB size) (RRB. !)
79
83
])
80
- , bgroup
84
+ , bgroup
81
85
" Append"
82
86
(appends
83
87
[ Append " Data.List" sampleList (++) force
@@ -89,7 +93,7 @@ main = do
89
93
, Append " Data.RRBVector" sampleRRB (RRB. ><) id
90
94
, Append " Data.Acc" sampleAcc (<>) id
91
95
])
92
- , bgroup
96
+ , bgroup
93
97
" Length"
94
98
(lengths
95
99
[ Length " Data.List" sampleList L. length
@@ -102,7 +106,7 @@ main = do
102
106
, Length " Data.RRBVector" sampleRRB length
103
107
, Length " Data.Acc" sampleAcc length
104
108
])
105
- , bgroup
109
+ , bgroup
106
110
" Stable Sort"
107
111
(sorts
108
112
[ Sort " Data.List" randomSampleList L. sort
@@ -111,7 +115,7 @@ main = do
111
115
, Sort " Data.Vector.Storable" randomSampleSVVector sortSVec
112
116
, Sort " Data.Sequence" randomSampleSeq S. sort
113
117
])
114
- , bgroup
118
+ , bgroup
115
119
" Replicate"
116
120
(replicators
117
121
[ Replicator " Data.List" L. replicate
@@ -122,7 +126,7 @@ main = do
122
126
, Replicator " Data.Sequence" S. replicate
123
127
, Replicator " Data.RRBVector" RRB. replicate
124
128
])
125
- , bgroup
129
+ , bgroup
126
130
" Min"
127
131
(mins
128
132
[ Min " Data.List" randomSampleList L. minimum
@@ -135,7 +139,7 @@ main = do
135
139
, Min " Data.RRBVector" randomSampleRRB minimum
136
140
, Min " Data.Acc" randomSampleAcc minimum
137
141
])
138
- , bgroup
142
+ , bgroup
139
143
" Max"
140
144
(maxs
141
145
[ Max " Data.List" randomSampleList L. maximum
@@ -148,7 +152,7 @@ main = do
148
152
, Max " Data.RRBVector" randomSampleRRB maximum
149
153
, Max " Data.Acc" randomSampleAcc maximum
150
154
])
151
- , bgroup
155
+ , bgroup
152
156
" Filter Element"
153
157
(let size = 10005
154
158
in removeElems
@@ -164,7 +168,7 @@ main = do
164
168
SV. filter
165
169
, RemoveElement " Data.Sequence" (sampleSeq size) S. filter
166
170
])
167
- , bgroup
171
+ , bgroup
168
172
" Filter By Index"
169
173
(let size = 10005
170
174
in removeByIndexes
@@ -178,82 +182,89 @@ main = do
178
182
(sampleSVVector size)
179
183
SV. ifilter
180
184
])
181
- ]
182
- where
185
+ ]
186
+
187
+ bench' groupTitle title i
188
+ | title == " Data.Vector"
189
+ = bench (title ++ " :" ++ show i)
190
+ | otherwise
191
+ = bcompare (" $NF == \" Data.Vector:" ++ show i ++ " \" && $(NF-1) == \" " ++ groupTitle ++ " \" " )
192
+ . bench (title ++ " :" ++ show i)
193
+
183
194
appends funcs =
184
195
[ env
185
196
(payload i)
186
- (\ p -> bench (title ++ " : " ++ show i) $ whnf (\ x -> forcer (func x x)) p)
197
+ (\ p -> bench' " Append " title i $ whnf (\ x -> forcer (func x x)) p)
187
198
| i <- [10 , 100 , 1000 , 10000 ]
188
199
, Append title payload func forcer <- funcs
189
200
]
190
201
conses funcs =
191
202
[ env
192
203
(sample i)
193
- (\ p -> bench (title ++ " : " ++ show i) (whnf (\ e -> func e p) 1 ))
194
- | i <- [10 , 100 , 1000 , 10000 ]
204
+ (\ p -> bench' " Consing " title i (whnf (\ e -> func e p) 1 ))
205
+ | i <- [10 , 100 , 1000 , 10000 ]
195
206
, Conser title sample func <- funcs
196
207
]
197
208
snocs funcs =
198
209
[ env
199
210
(sample i)
200
- (\ p -> bench (title ++ " : " ++ show i) (whnf (\ e -> func p e) 1 ))
211
+ (\ p -> bench' " Snocing " title i (whnf (\ e -> func p e) 1 ))
201
212
| i <- [10 , 100 , 1000 , 10000 ]
202
213
, Snocer title sample func <- funcs
203
214
]
204
215
replicators funcs =
205
- [ bench (title ++ " : " ++ show i) $ nf (\ (x, y) -> func x y) (i, 1234 )
216
+ [ bench' " Replicate " title i $ nf (\ (x, y) -> func x y) (i, 1234 )
206
217
| i <- [10 , 100 , 1000 , 10000 ]
207
218
, Replicator title func <- funcs
208
219
]
209
220
indexes funcs =
210
221
[ env
211
222
payload
212
- (\ p -> bench (title ++ " : " ++ show index) $ nf (\ x -> func p x) index)
223
+ (\ p -> bench' " Indexing " title index $ nf (\ x -> func p x) index)
213
224
| index <- [10 , 100 , 1000 , 10000 ]
214
225
, Indexing title payload func <- funcs
215
226
]
216
227
lengths funcs =
217
228
[ env
218
229
(payload len)
219
- (\ p -> bench (title ++ " : " ++ ( show len)) $ nf (\ x -> func x) p)
230
+ (\ p -> bench' " Length " title len $ nf (\ x -> func x) p)
220
231
| len <- [10 , 100 , 1000 , 10000 ]
221
232
, Length title payload func <- funcs
222
233
]
223
234
mins funcs =
224
235
[ env
225
236
(payload len)
226
- (\ p -> bench (title ++ " : " ++ ( show len)) $ nf (\ x -> func x) p)
237
+ (\ p -> bench' " Min " title len $ nf (\ x -> func x) p)
227
238
| len <- [10 , 100 , 1000 , 10000 ]
228
239
, Min title payload func <- funcs
229
240
]
230
241
maxs funcs =
231
242
[ env
232
243
(payload len)
233
- (\ p -> bench (title ++ " : " ++ ( show len)) $ nf (\ x -> func x) p)
244
+ (\ p -> bench' " Max " title len $ nf (\ x -> func x) p)
234
245
| len <- [10 , 100 , 1000 , 10000 ]
235
246
, Max title payload func <- funcs
236
247
]
237
248
sorts funcs =
238
249
[ env
239
250
(payload len)
240
- (\ p -> bench (title ++ " : " ++ ( show len)) $ nf (\ x -> func x) p)
251
+ (\ p -> bench' " Stable Sort " title len $ nf (\ x -> func x) p)
241
252
| len <- [10 , 100 , 1000 , 10000 ]
242
253
, Sort title payload func <- funcs
243
254
]
244
255
removeElems funcs =
245
256
[ env
246
257
payload
247
258
(\ p ->
248
- bench (title ++ " : " ++ show relem) $ nf (\ x -> func (/= relem) x) p)
259
+ bench' " Filter Element " title relem $ nf (\ x -> func (/= relem) x) p)
249
260
| relem <- [1 , 100 , 1000 , 10000 :: Int ]
250
261
, RemoveElement title payload func <- funcs
251
262
]
252
263
removeByIndexes funcs =
253
264
[ env
254
265
payload
255
266
(\ p ->
256
- bench (title ++ " : " ++ show relem) $
267
+ bench' " Filter By Index " title relem $
257
268
nf (\ x -> func (\ index _ -> index /= relem) x) p)
258
269
| relem <- [1 , 100 , 1000 , 10000 :: Int ]
259
270
, RemoveByIndex title payload func <- funcs
0 commit comments