forked from ku-fpg/hermit-streamfusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntuition.hs
40 lines (33 loc) · 905 Bytes
/
Intuition.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE BangPatterns, RankNTypes #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_GHC -fspec-constr #-}
{-# OPTIONS_GHC -fdicts-cheap #-}
module Main where
import Criterion.Main as C
import HERMIT.Optimization.StreamFusion.List
f :: Int -> Int
f n = foldl (+) 0 (concatMap (\x -> enumFromTo 1 x) (enumFromTo 1 n))
{-# NOINLINE f #-}
g :: Int -> Int
g n = foldl (+) 0 (flatten mk step (enumFromTo 1 n))
where
mk x = (1,x)
{-# INLINE mk #-}
step (i,max)
| i<=max = Yield i (i+1,max)
| otherwise = Done
{-# INLINE step #-}
{-# NOINLINE g #-}
main = do
print $ f 1000
print $ g 1000
defaultMain
[ bgroup "concat tests / 100"
[ bench "f" $ whnf f 100
, bench "g" $ whnf g 100
]
, bgroup "concat tests / 1000"
[ bench "f" $ whnf f 1000
, bench "g" $ whnf g 1000
]
]