Skip to content

Commit

Permalink
Cleanup bench and update GHC (#8)
Browse files Browse the repository at this point in the history
* remove random-bytestring dependency of benchmarks

* remove support for GHC < 9
  • Loading branch information
larskuhtz authored Oct 13, 2023
1 parent 0dba55d commit a71a367
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cabal-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ghc: ['8.10', '9.0', '9.2', '9.4', '9.6']
ghc: ['9.0', '9.2', '9.4', '9.6', '9.8']
cabal: ['3.10']
os: ['ubuntu-22.04', 'ubuntu-20.04', 'macOS-latest']

Expand Down
22 changes: 8 additions & 14 deletions bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
-- Maintainer: Lars Kuhtz <lars@kadena.io>
-- Stability: experimental
--
-- TODO
--
module Main
( main
) where

import Control.DeepSeq
import Control.Monad
import Control.Monad.Trans.State.Strict

import Criterion
import Criterion.Main
Expand All @@ -35,16 +35,12 @@ import qualified "cryptonite" Crypto.Hash as CR

import qualified Data.ByteArray as BA
import qualified Data.ByteString as B
import Data.ByteString.Random.MWC
import qualified Data.HashTree as HT
import Data.Maybe

import GHC.Generics

import Numeric.Natural

import System.Random
import qualified System.Random.MWC as MWC

-- internal modules

Expand All @@ -55,7 +51,7 @@ import qualified Data.MerkleLog as ML

main :: IO ()
main = defaultMain
[ env globalEnv $ \ ~e -> bgroup "main"
[ env (return globalEnv) $ \ ~e -> bgroup "main"
[ bgroup "create tree"
[ bgroup "SHA512t_256"
[ createBench @(ML SHA512t_256) e
Expand Down Expand Up @@ -125,14 +121,12 @@ leafMaxSize = 1000

type GlobalEnv = [B.ByteString]

globalEnv :: IO GlobalEnv
globalEnv = do
gen <- MWC.create
traverse (randomGen gen) (randomNats leafCount)
globalEnv :: GlobalEnv
globalEnv = evalState (replicateM leafCount genBytes) (mkStdGen 1)
where

randomNats :: Int -> [Natural]
randomNats i = fmap fromIntegral $ take i $ randomRs @Int (0,leafMaxSize) $ mkStdGen 1
genBytes = do
len <- state $ randomR (0, leafMaxSize)
state $ genByteString len

-- -------------------------------------------------------------------------- --
-- Create Benchmark
Expand Down
20 changes: 20 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
packages: merkle-log.cabal
optimization: 2

-- The following are all dependencies of GHC.
--
allow-newer: *:Cabal
allow-newer: *:Cabal-syntax
allow-newer: *:array
allow-newer: *:base
allow-newer: *:bytestring
allow-newer: *:deepseq
allow-newer: *:ghc
allow-newer: *:ghc-boot-th
allow-newer: *:ghc-prim
allow-newer: *:integer-gmp
allow-newer: *:pretty
allow-newer: *:template-haskell
allow-newer: *:text

constraints: aeson>2
7 changes: 3 additions & 4 deletions merkle-log.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ maintainer: Lars Kuhtz <lars@kadena.io>
copyright: Copyright (c) 2019-2023, Kadena LLC
category: Data
tested-with:
GHC==9.8
GHC==9.6
GHC==9.4
GHC==9.2
GHC==9.0
GHC==8.10
extra-source-files:
README.md
CHANGELOG.md
Expand Down Expand Up @@ -86,7 +86,6 @@ benchmark benchmarks
, deepseq >=1.4
, hash-tree >=0.0
, memory >=0.14
, mwc-random >=0.14
, random >=1.1
, random-bytestring >=0.1
, random >=1.2
, transformers >= 0.6

0 comments on commit a71a367

Please sign in to comment.