Skip to content

Instantly share code, notes, and snippets.

@gregnwosu
Created November 1, 2016 20:45
Show Gist options
  • Save gregnwosu/432a0e493e5aa520270a354e60c9d70e to your computer and use it in GitHub Desktop.
Save gregnwosu/432a0e493e5aa520270a354e60c9d70e to your computer and use it in GitHub Desktop.
sequence slower to index?
module SequenceTest where
import Criterion.Main
import qualified Data.Sequence as SQ
s :: SQ.Seq Int
s = SQ.fromList [1..9100]
lists :: [[Int]]
lists = replicate 10 [1..1000000]
seqs :: [SQ.Seq Int]
seqs = replicate 10 (SQ.fromList [1..1000000])
l1 = [0]
s1 = SQ.singleton 0
l :: [Int]
l = [1..9100]
main =
defaultMain
[
-- bench "list concat" $ nf (l ++ ) l1,
-- bench "seq concat " $ nf (s SQ.>< ) s1,
-- bench "list mconcat " $ nf mconcat lists,
-- bench "seqs mconcat" $ nf mconcat seqs,
bench "list index" $ whnf (\xs -> xs !! 9001) l,
bench "seq index" $ whnf (`SQ.index` 9001) s
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment