Skip to content

Commit b5ae5cf

Browse files
authored
Merge pull request #370 from well-typed/dcoutts/macro-benchmark
Resurrect the macro benchmarks and fix various warnings
2 parents 97fae28 + 9d40cd9 commit b5ae5cf

File tree

31 files changed

+763
-4323
lines changed

31 files changed

+763
-4323
lines changed

cabal.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ benchmarks: True
1111
-- Needed for serialise benchmarks
1212
allow-newer:
1313
store-core:text
14+
15+
package cborg
16+
ghc-options: -Werror -Wno-error=deprecations
17+
18+
package serialise
19+
ghc-options: -Werror

cborg/cborg.cabal

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ flag optimize-gmp
6464

6565
library
6666
default-language: Haskell2010
67-
ghc-options: -Wall
6867
include-dirs: src/cbits
6968
hs-source-dirs: src
7069

@@ -109,7 +108,10 @@ library
109108
else
110109
build-depends: integer-gmp >= 1.0 && < 2
111110

112-
ghc-options: -Wcompat -Wnoncanonical-monad-instances
111+
ghc-options: -Wall -Wcompat
112+
113+
if impl(ghc >= 9.0)
114+
ghc-options: -Wunused-packages
113115

114116
test-suite cborg-tests
115117
type: exitcode-stdio-1.0
@@ -118,7 +120,7 @@ test-suite cborg-tests
118120

119121
default-language: Haskell2010
120122
ghc-options:
121-
-Wall -fno-warn-orphans
123+
-Wall -Wno-orphans
122124
-threaded -rtsopts "-with-rtsopts=-N2"
123125

124126
other-modules:

cborg/src/Codec/CBOR/ByteArray.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import GHC.Exts (IsList(..), IsString(..))
3636
import qualified Data.Primitive.ByteArray as Prim
3737
import qualified Data.ByteString as BS
3838
import qualified Data.ByteString.Short as BSS
39+
#if !MIN_VERSION_bytestring(0,11,1)
3940
import qualified Data.ByteString.Short.Internal as BSS
41+
#endif
4042
import qualified Data.ByteString.Builder as BSB
4143

4244
import qualified Codec.CBOR.ByteArray.Sliced as Sliced
@@ -49,10 +51,18 @@ sizeofByteArray :: ByteArray -> Int
4951
sizeofByteArray (BA ba) = Prim.sizeofByteArray ba
5052

5153
fromShortByteString :: BSS.ShortByteString -> ByteArray
54+
#if MIN_VERSION_bytestring(0,12,0)
55+
fromShortByteString (BSS.ShortByteString ba) = BA ba
56+
#else
5257
fromShortByteString (BSS.SBS ba) = BA (Prim.ByteArray ba)
58+
#endif
5359

5460
toShortByteString :: ByteArray -> BSS.ShortByteString
61+
#if MIN_VERSION_bytestring(0,12,0)
62+
toShortByteString (BA ba) = BSS.ShortByteString ba
63+
#else
5564
toShortByteString (BA (Prim.ByteArray ba)) = BSS.SBS ba
65+
#endif
5666

5767
fromByteString :: BS.ByteString -> ByteArray
5868
fromByteString = fromShortByteString . BSS.toShort

cborg/src/Codec/CBOR/ByteArray/Sliced.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ import qualified Data.Primitive.ByteArray as Prim
3838
import qualified Data.ByteString as BS
3939
import qualified Data.ByteString.Unsafe as BS
4040
import qualified Data.ByteString.Short as BSS
41+
#if !MIN_VERSION_bytestring(0,11,1)
4142
import qualified Data.ByteString.Short.Internal as BSS
43+
#endif
4244
import qualified Data.ByteString.Builder as BSB
4345
import qualified Data.ByteString.Builder.Internal as BSB
4446

@@ -47,7 +49,11 @@ import Codec.CBOR.ByteArray.Internal
4749
data SlicedByteArray = SBA {unSBA :: !Prim.ByteArray, offset :: !Int, length :: !Int}
4850

4951
fromShortByteString :: BSS.ShortByteString -> SlicedByteArray
52+
#if MIN_VERSION_bytestring(0,12,0)
53+
fromShortByteString (BSS.ShortByteString ba) = fromByteArray ba
54+
#else
5055
fromShortByteString (BSS.SBS ba) = fromByteArray (Prim.ByteArray ba)
56+
#endif
5157

5258
fromByteString :: BS.ByteString -> SlicedByteArray
5359
fromByteString = fromShortByteString . BSS.toShort

cborg/tests/Tests/Boundary.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE RankNTypes #-}
55
{-# LANGUAGE ScopedTypeVariables #-}
66
{-# LANGUAGE TypeFamilies #-}
7+
{-# LANGUAGE TypeOperators #-}
78
{-# LANGUAGE UndecidableInstances #-}
89
module Tests.Boundary
910
( testTree -- :: TestTree

cborg/tests/Tests/PreEncoded.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module Tests.PreEncoded (
22
testTree
33
) where
44

5-
import Data.Monoid (Monoid(mconcat))
6-
75
import Codec.CBOR.Term (Term, encodeTerm)
86
import Codec.CBOR.FlatTerm (FlatTerm, toFlatTerm, TermToken(..))
97
import Codec.CBOR.Write (toStrictByteString, toLazyByteString)

cborg/tests/Tests/Reference/Generators.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Numeric (showHex)
3232
import Numeric.Half as Half
3333
import GHC.Float (float2Double)
3434
import Data.Proxy
35+
import Data.Kind
3536

3637
import Foreign
3738
import System.IO.Unsafe
@@ -227,7 +228,7 @@ class (RealFloat n, Integral (FloatWord n), Show (FloatWord n),
227228
exponentBits :: Proxy n -> Int
228229
significandBits :: Proxy n -> Int
229230

230-
type FloatWord n :: *
231+
type FloatWord n :: Type
231232
wordToFloating :: FloatWord n -> n
232233
--floatingToWord :: n -> FloatWord n
233234

cborg/tests/Tests/Reference/Implementation.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ import qualified Data.ByteString as BS
7979
import qualified Data.ByteString.Lazy as LBS
8080
import qualified Data.Text as T
8181
import qualified Data.Text.Encoding as T
82-
import Data.Monoid ((<>))
8382
import Control.Monad (ap)
8483

8584
import Test.QuickCheck.Arbitrary
@@ -107,11 +106,10 @@ instance Functor Decoder where
107106
fmap f a = a >>= return . f
108107

109108
instance Applicative Decoder where
110-
pure = return
111-
(<*>) = ap
109+
pure x = Decoder (\ws -> Just (x, ws))
110+
(<*>) = ap
112111

113112
instance Monad Decoder where
114-
return x = Decoder (\ws -> Just (x, ws))
115113
d >>= f = Decoder (\ws -> case runDecoder d ws of
116114
Nothing -> Nothing
117115
Just (x, ws') -> runDecoder (f x) ws')

cborg/tests/Tests/Regress/Issue162.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Tests.Regress.Issue162 ( testTree ) where
22

33
import Control.Monad (void)
4-
import Control.Applicative ((<$), (<*))
54
import Data.Word
65
import Data.ByteString.Lazy (ByteString)
76
import qualified Data.ByteString.Lazy as LBS

serialise/bench/versus/Macro.hs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
module Macro
23
( benchmarks -- :: [Benchmark]
34
) where
@@ -9,40 +10,40 @@ import qualified Data.ByteString as B
910
import qualified Data.ByteString.Lazy as BS
1011
import qualified Codec.Compression.GZip as GZip
1112

12-
import qualified Macro.Types as Types
13-
import qualified Macro.MemSize
14-
import Macro.DeepSeq ()
13+
import Distribution.PackageDescription (GenericPackageDescription)
1514
import qualified Macro.Load as Load
1615

1716
import qualified Macro.ReadShow as ReadShow
1817
import qualified Macro.PkgBinary as PkgBinary
1918
import qualified Macro.PkgCereal as PkgCereal
19+
#if __GLASGOW_HASKELL__ >= 900
20+
-- ghc-8.x runs out of memory compiling this module:
2021
import qualified Macro.PkgAesonGeneric as PkgAesonGeneric
22+
#endif
2123
import qualified Macro.PkgAesonTH as PkgAesonTH
2224
import qualified Macro.PkgStore as PkgStore
2325

2426
import qualified Macro.CBOR as CBOR
2527

26-
readBigTestData :: IO [Types.GenericPackageDescription]
27-
readBigTestData = do
28-
Right pkgs_ <- fmap (Load.readPkgIndex . GZip.decompress)
29-
(BS.readFile "bench/data/01-index.tar.gz")
30-
let tstdata = take 100 pkgs_
31-
return tstdata
28+
readBigTestData :: IO [GenericPackageDescription]
29+
readBigTestData =
30+
fmap (take 100000 . Load.readPkgIndex . GZip.decompress)
31+
(BS.readFile "serialise/bench/data/01-index.tar.gz")
3232

3333
benchmarks :: [Benchmark]
3434
benchmarks =
3535
[ env readBigTestData $ \tstdata ->
3636
bgroup "reference"
3737
[ bench "deepseq" (whnf rnf tstdata)
38-
, bench "memSize" (whnf (flip Macro.MemSize.memSize 0) tstdata)
3938
]
4039

4140
, env readBigTestData $ \tstdata ->
4241
bgroup "encoding"
4342
[ bench "binary" (whnf perfEncodeBinary tstdata)
4443
, bench "cereal" (whnf perfEncodeCereal tstdata)
44+
#if __GLASGOW_HASKELL__ >= 900
4545
, bench "aeson generic" (whnf perfEncodeAesonGeneric tstdata)
46+
#endif
4647
, bench "aeson TH" (whnf perfEncodeAesonTH tstdata)
4748
, bench "read/show" (whnf perfEncodeReadShow tstdata)
4849
, bench "cbor" (whnf perfEncodeCBOR tstdata)
@@ -57,8 +58,10 @@ benchmarks =
5758
$ \tstdataC -> bench "cereal" (whnf perfDecodeCereal tstdataC)
5859
, env (return $ combineChunks $ PkgAesonTH.serialise tstdata)
5960
$ \tstdataA -> bgroup "aeson"
60-
[ bench "generic" (whnf perfDecodeAesonGeneric tstdataA)
61-
, bench "TH" (whnf perfDecodeAesonTH tstdataA)
61+
[ bench "TH" (whnf perfDecodeAesonTH tstdataA)
62+
#if __GLASGOW_HASKELL__ >= 900
63+
, bench "generic" (whnf perfDecodeAesonGeneric tstdataA)
64+
#endif
6265
]
6366
, env (return $ combineChunks $ ReadShow.serialise tstdata)
6467
$ \tstdataS -> bench "read/show" (whnf perfDecodeReadShow tstdataS)
@@ -76,8 +79,10 @@ benchmarks =
7679
$ \tstdataC -> bench "cereal" (nf perfDecodeCereal tstdataC)
7780
, env (return $ combineChunks $ PkgAesonTH.serialise tstdata)
7881
$ \tstdataA -> bgroup "aeson"
79-
[ bench "generic" (nf perfDecodeAesonGeneric tstdataA)
80-
, bench "TH" (nf perfDecodeAesonTH tstdataA)
82+
[ bench "TH" (nf perfDecodeAesonTH tstdataA)
83+
#if __GLASGOW_HASKELL__ >= 900
84+
, bench "generic" (nf perfDecodeAesonGeneric tstdataA)
85+
#endif
8186
]
8287

8388
, env (return $ combineChunks $ ReadShow.serialise tstdata)
@@ -89,34 +94,40 @@ benchmarks =
8994
]
9095
]
9196
where
92-
perfEncodeBinary, perfEncodeCereal, perfEncodeAesonGeneric,
97+
perfEncodeBinary, perfEncodeCereal,
9398
perfEncodeAesonTH, perfEncodeReadShow,
9499
perfEncodeCBOR
95-
:: [Types.GenericPackageDescription] -> Int64
100+
:: [GenericPackageDescription] -> Int64
96101

97102

98103
perfEncodeBinary = BS.length . PkgBinary.serialise
99104
perfEncodeCereal = BS.length . PkgCereal.serialise
100-
perfEncodeAesonGeneric = BS.length . PkgAesonGeneric.serialise
101105
perfEncodeAesonTH = BS.length . PkgAesonTH.serialise
102106
perfEncodeReadShow = BS.length . ReadShow.serialise
103107
perfEncodeCBOR = BS.length . CBOR.serialise
108+
#if __GLASGOW_HASKELL__ >= 900
109+
perfEncodeAesonGeneric :: [GenericPackageDescription] -> Int64
110+
perfEncodeAesonGeneric = BS.length . PkgAesonGeneric.serialise
111+
#endif
104112

105-
perfDecodeBinary, perfDecodeCereal, perfDecodeAesonGeneric,
113+
perfDecodeBinary, perfDecodeCereal,
106114
perfDecodeAesonTH, perfDecodeReadShow,
107115
perfDecodeCBOR
108-
:: BS.ByteString -> [Types.GenericPackageDescription]
116+
:: BS.ByteString -> [GenericPackageDescription]
109117

110118
perfDecodeBinary = PkgBinary.deserialise
111119
perfDecodeCereal = PkgCereal.deserialise
112-
perfDecodeAesonGeneric = PkgAesonGeneric.deserialise
113120
perfDecodeAesonTH = PkgAesonTH.deserialise
114121
perfDecodeReadShow = ReadShow.deserialise
115122
perfDecodeCBOR = CBOR.deserialise
123+
#if __GLASGOW_HASKELL__ >= 900
124+
perfDecodeAesonGeneric :: BS.ByteString -> [GenericPackageDescription]
125+
perfDecodeAesonGeneric = PkgAesonGeneric.deserialise
126+
#endif
116127

117-
perfDecodeStore :: B.ByteString -> [Types.GenericPackageDescription]
128+
perfDecodeStore :: B.ByteString -> [GenericPackageDescription]
118129
perfDecodeStore = PkgStore.deserialise
119-
perfEncodeStore :: [Types.GenericPackageDescription] -> Int
130+
perfEncodeStore :: [GenericPackageDescription] -> Int
120131
perfEncodeStore = B.length . PkgStore.serialise
121132

122133
-- Convert any lazy ByteString to ByteString lazy bytestring

0 commit comments

Comments
 (0)