Skip to content

Commit

Permalink
Fix benchmark build (#196)
Browse files Browse the repository at this point in the history
* Fix benchmarks (rebased)

* Prevent build with GHC < 7.2

… which currently fails with
    BenchAll.hs:173:55:
        No instance for (Random Word8)
          arising from a use of `random'
        Possible fix: add an instance declaration for (Random Word8)
        In the second argument of `(.)', namely `random'
        In the second argument of `S.unfoldrN', namely `(Just . random)'
        In the second argument of `(.)', namely
          `S.unfoldrN 10000 (Just . random)'

* Remove stack.yaml

blaze-builder-0.3.* is incompatible with GHC >= 8.4

With --allow-newer it fails to build with:

    /tmp/stack26342/blaze-builder-0.3.3.4/Blaze/ByteString/Builder/Internal/Types.hs:71:10: error:
        • No instance for (Semigroup Builder)
           arising from the superclasses of an instance declaration
        • In the instance declaration for ‘Monoid Builder’
       |
    71 | instance Monoid Builder where
       |          ^^^^^^^^^^^^^^

* Turn off building bench-bytestring-builder for GHC >= 8.4

* Use CPP to make bench-bytestring-builder buildable with GHC-8.4+

* Simply relax the bounds on blaze-builder for GHC >= 8.4

Co-authored-by: Sylvain Henry <[email protected]>
  • Loading branch information
sjakobi and hsyl20 authored May 6, 2020
1 parent 95fe6bd commit 38ad056
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
5 changes: 3 additions & 2 deletions bench/BenchAll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import qualified "bytestring" Data.ByteString.Lazy as OldL
import Foreign

import System.Random
import Paths_bench_bytestring


------------------------------------------------------------------------------
Expand Down Expand Up @@ -133,7 +134,7 @@ benchFE name = benchBE name . P.liftFixedToBounded
{-# INLINE benchBE #-}
benchBE :: String -> BoundedPrim Int -> Benchmark
benchBE name e =
bench (name ++" (" ++ show nRepl ++ ")") $ benchIntEncodingB nRepl e
bench (name ++" (" ++ show nRepl ++ ")") $ whnfIO (benchIntEncodingB nRepl e)

-- We use this construction of just looping through @n,n-1,..,1@ to ensure that
-- we measure the speed of the encoding and not the speed of generating the
Expand Down Expand Up @@ -166,7 +167,7 @@ w :: Int -> Word8
w = fromIntegral

hashWord8 :: Word8 -> Word8
hashWord8 = fromIntegral . hashInt . w
hashWord8 = fromIntegral . hashInt . fromIntegral

partitionStrict p = nf (S.partition p) . randomStrict $ mkStdGen 98423098
where randomStrict = fst . S.unfoldrN 10000 (Just . random)
Expand Down
53 changes: 48 additions & 5 deletions bench/bench-bytestring.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,34 @@ executable bench-bytestring-builder
hs-source-dirs: . ..
main-is: BenchAll.hs

build-depends: base >= 4 && < 5
build-depends: base >= 4.4 && < 5
, ghc-prim
, deepseq >= 1.2
, criterion >= 0.5
, blaze-textual == 0.2.*
-- There is no point using blaze-builder-0.4+ as that
-- version is just a wrapper around bytestring itself,
-- abd so a comparison benchmark would have no purpose.
, blaze-builder == 0.3.*
-- we require bytestring due to benchmarking against
-- blaze-textual, which uses blaze-builder
, bytestring >= 0.9
, random
other-modules:
Data.ByteString
Data.ByteString.Builder
Data.ByteString.Builder.ASCII
Data.ByteString.Builder.Extra
Data.ByteString.Builder.Internal
Data.ByteString.Builder.Prim
Data.ByteString.Builder.Prim.ASCII
Data.ByteString.Builder.Prim.Binary
Data.ByteString.Builder.Prim.Internal
Data.ByteString.Builder.Prim.Internal.Base16
Data.ByteString.Builder.Prim.Internal.Floating
Data.ByteString.Builder.Prim.Internal.UncheckedShifts
Data.ByteString.Internal
Data.ByteString.Lazy
Data.ByteString.Lazy.Internal
Data.ByteString.Short.Internal
Data.ByteString.Unsafe
Paths_bench_bytestring

-- cabal complains about ../ dirs. However, this is better than symlinks,
-- which probably don't work on windows.
Expand All @@ -63,6 +78,15 @@ executable bench-bytestring-builder
-fdicts-cheap
-fspec-constr-count=6

-- Since blaze-builder-0.4+ is just a wrapper around bytestring, we prefer
-- building with blaze-builder-0.3.*. However blaze-builder-0.3.* isn't
-- compatible with GHC-8.4+, so we relax the version bounds when building
-- with these GHC versions.
if impl(ghc >= 8.4)
build-depends: blaze-builder >= 0.3 && < 0.5
else
build-depends: blaze-builder == 0.3.*

-- flags for the decimal integer serialization code
if impl(ghc >= 6.11)
if !flag(integer-simple)
Expand Down Expand Up @@ -133,6 +157,25 @@ executable bench-builder-boundscheck
-fdicts-cheap
-fspec-constr-count=6
default-language: Haskell98
other-modules:
Data.ByteString
Data.ByteString.Builder
Data.ByteString.Builder.ASCII
Data.ByteString.Builder.Extra
Data.ByteString.Builder.Internal
Data.ByteString.Builder.Prim
Data.ByteString.Builder.Prim.ASCII
Data.ByteString.Builder.Prim.Binary
Data.ByteString.Builder.Prim.Internal
Data.ByteString.Builder.Prim.Internal.Base16
Data.ByteString.Builder.Prim.Internal.Floating
Data.ByteString.Builder.Prim.Internal.UncheckedShifts
Data.ByteString.Internal
Data.ByteString.Lazy
Data.ByteString.Lazy.Internal
Data.ByteString.Short.Internal
Data.ByteString.Unsafe
Paths_bench_bytestring

--executable bench-builder-csv
-- hs-source-dirs: .. .
Expand Down

0 comments on commit 38ad056

Please sign in to comment.