File: deque.hs

package info (click to toggle)
haskell-mutable-containers 0.3.4.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 132 kB
  • sloc: haskell: 888; makefile: 5
file content (39 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies    #-}
import Control.Monad
import Gauge.Main
import Data.Mutable
import Data.Sequence      (Seq)

test :: (MCState c ~ PrimState IO, CollElement c ~ Int, MutableDeque c)
     => String
     -> (c -> c)
     -> Benchmark
test name forceType = bench name $ whnfIO $ do
    let x = 5 :: Int
    coll <- fmap forceType newColl
    replicateM_ 500 $ pushFront coll x
    replicateM_ 500 $ pushBack coll x
    replicateM_ 200 $ void $ popFront coll
    replicateM_ 200 $ void $ popBack coll
    replicateM_ 500 $ do
        pushBack coll x
        pushFront coll x
        void $ popFront coll
    replicateM_ 500 $ do
        pushBack coll x
        pushFront coll x
    replicateM_ 500 $ do
        pushBack coll x
        void $ popFront coll
{-# INLINE test #-}

main :: IO ()
main = defaultMain
    [ test "IORef [Int]" (id :: IORef [Int] -> IORef [Int])
    , test "IORef (Seq Int)" (id :: IORef (Seq Int) -> IORef (Seq Int))
    , test "UDeque" asUDeque
    , test "SDeque" asSDeque
    , test "BDeque" asBDeque
    , test "DLList" asDLList
    ]