Skip to content

Instantly share code, notes, and snippets.

@ndmitchell
Created April 23, 2017 19:52
Show Gist options
  • Save ndmitchell/c418c4092e6c0918d6e91795cfa2c137 to your computer and use it in GitHub Desktop.
Save ndmitchell/c418c4092e6c0918d6e91795cfa2c137 to your computer and use it in GitHub Desktop.
DList benchmarks
{-# 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