Commit a5a44704 authored by Ben Gamari's avatar Ben Gamari 🐢
Browse files

Initial commit

parents
import qualified Data.DList as DList
import qualified Data.Sequence as Seq
import Data.Foldable
import Criterion.Main
rebuildSeq :: [a] -> Seq.Seq a
rebuildSeq = go mempty
where
go :: Seq.Seq a -> [a] -> Seq.Seq a
go acc (x:xs) = go (acc Seq.|> x) xs
go acc [] = acc
rebuildList :: [a] -> [a]
rebuildList = go mempty
where
go :: [a] -> [a] -> [a]
go acc (x:xs) = go (x : acc) xs
go acc [] = reverse acc
rebuildDList :: [a] -> [a]
rebuildDList = go mempty
where
go :: DList.DList a -> [a] -> [a]
go acc (x:xs) = go (acc <> DList.singleton x) xs
go acc [] = toList acc
rebuildBenchmarks :: Int -> Benchmark
rebuildBenchmarks len = bgroup ("length="++show len)
[ bench "sequence" $ whnf (length . rebuildSeq) xs
, bench "dlist" $ whnf (length . rebuildDList) xs
, bench "list" $ whnf (length . rebuildList) xs
]
where
xs = [1..len]
main :: IO ()
main = defaultMain
[ rebuildBenchmarks 1
, rebuildBenchmarks 2
, rebuildBenchmarks 5
, rebuildBenchmarks 10
, rebuildBenchmarks 20
, rebuildBenchmarks 50
, rebuildBenchmarks 100
, rebuildBenchmarks 200
]
cabal-version: >=1.10
name: append-benchmark
version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
license: BSD3
author: Ben Gamari
maintainer: ben@smart-cactus.org
copyright: (c) 2020 Ben Gamari
build-type: Simple
extra-source-files: CHANGELOG.md
executable append-benchmark
main-is: Main.hs
build-depends: base >=4.13 && <4.14,
containers,
dlist,
criterion
default-language: Haskell2010
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment