Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. {-# OPTIONS_GHC -O2 #-}
  2. import Control.Monad
  3. import Control.Exception
  4. import System.Time.Extra
  5.  
  6. import Criterion.Main
  7.  
  8. type DList a = [a] -> [a]
  9.  
  10. dTo f = f []
  11. dSnoc f x = f . (x:)
  12.  
  13. data DType a = Nil | Snoc (DType a) a
  14.  
  15. tTo x = f x []
  16. where f Nil x = x
  17. f (Snoc xs x) acc = f xs (x:acc)
  18. tSnoc f x = Snoc f x
  19.  
  20. build nil snoc i = f i
  21. where f 0 = nil
  22. f i = snoc (build nil snoc (i-1)) i
  23.  
  24. count = 1000 :: Int
  25.  
  26. main = defaultMain [
  27. bgroup "dlist" [ bench "dlist" $ nf (dTo . build id dSnoc) count
  28. , bench "snoc" $ nf (tTo . build Nil tSnoc) count
  29. , bench "reverse" $ nf (reverse . build [] (flip (:))) count
  30. ]
  31. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement