Created
April 23, 2017 19:52
-
-
Save ndmitchell/c418c4092e6c0918d6e91795cfa2c137 to your computer and use it in GitHub Desktop.
DList benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment