File: Mini.hs

package info (click to toggle)
haskell-serialise 0.2.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 596 kB
  • sloc: haskell: 6,811; makefile: 3
file content (62 lines) | stat: -rw-r--r-- 1,900 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Mini
  ( benchmarks -- :: [Benchmark]
  ) where
import           System.FilePath

import           Criterion.Main
import qualified Data.ByteString        as B
import qualified Data.ByteString.Lazy   as BS

import           Macro.DeepSeq ()
import qualified Macro.PkgBinary as PkgBinary
import qualified Macro.PkgCereal as PkgCereal
import qualified Macro.PkgStore  as PkgStore
import qualified Macro.CBOR as CBOR


benchmarks :: [Benchmark]
benchmarks =
  [ bgroup "decode-index"
      [ bgroup "binary"
          [ envBinary $ \v ->
              bench "deserialise" $ nf PkgBinary.deserialise v
          ]
      , bgroup "cereal"
          [ envCereal $ \v ->
              bench "deserialise" $ nf PkgCereal.deserialise v
          ]
      , bgroup "store"
          [ envStore $ \v ->
              bench "deserialise" $ nf PkgStore.deserialise v
          ]
      , bgroup "cbor"
          [ envCBOR $ \v ->
              bench "deserialise" $ nf CBOR.deserialise v
          ]
      ]
  , bgroup "decode-index-noaccum"
      [ bgroup "binary"
          [ envBinary $ \v ->
              bench "deserialise" $ nf PkgBinary.deserialiseNull v
          ]
      , bgroup "cereal"
          [ envCereal $ \v ->
              bench "deserialise" $ nf PkgCereal.deserialiseNull v
          ]
      , bgroup "cbor"
          [ envCBOR $ \v ->
              bench "deserialise" $ nf CBOR.deserialiseNull v
          ]
      ]
  ]
  where
    -- Helpers for using Criterion environments.
    envBinary = env (fmap BS.fromStrict (readBin "binary"))
    envCereal = env (fmap BS.fromStrict (readBin "cereal"))
    envStore  = env (readBin "store")
    envCBOR   = env (fmap BS.fromStrict (readBin "cbor"))

    -- | Read one of the pre-encoded binary files out of the
    -- data directory.
    readBin :: FilePath -> IO B.ByteString
    readBin f = B.readFile ("bench" </> "data" </> f <.> "bin")