Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# OPTIONS_GHC -O2 #-}
- import Control.Monad
- import Control.Exception
- import System.Time.Extra
- import Criterion.Main
- type DList a = [a] -> [a]
- dTo f = f []
- dSnoc f x = f . (x:)
- data DType a = Nil | Snoc (DType a) a
- tTo x = f x []
- where f Nil x = x
- f (Snoc xs x) acc = f xs (x:acc)
- tSnoc f x = Snoc f x
- build nil snoc i = f i
- where f 0 = nil
- f i = snoc (build nil snoc (i-1)) i
- count = 1000 :: Int
- main = defaultMain [
- bgroup "dlist" [ bench "dlist" $ nf (dTo . build id dSnoc) count
- , bench "snoc" $ nf (tTo . build Nil tSnoc) count
- , bench "reverse" $ nf (reverse . build [] (flip (:))) count
- ]
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement