Skip to content

Commit bc283b4

Browse files
committed
Adds benchmarking code.
1 parent 98d8aa0 commit bc283b4

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

bench/src/Bench.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Bench where
2+
3+
import Prelude hiding (writeFile)
4+
import Data.Binary (decodeFile)
5+
import Data.BitCode
6+
import Data.BitCode.Writer (emitTopLevel)
7+
import Data.BitCode.Writer.Monad (writeFile)
8+
import Data.BitCode.Writer.Combinators (withHeader)
9+
10+
import Criterion.Main
11+
12+
--------------------------------------------------------------------------------
13+
-- Reading a serialized module.
14+
readModule :: FilePath -> IO [BitCode]
15+
readModule = decodeFile
16+
17+
writeModule :: FilePath -> [BitCode] -> IO ()
18+
writeModule f = writeFile f . withHeader True . emitTopLevel
19+
20+
main :: IO ()
21+
main = defaultMain [
22+
bgroup "writer"
23+
[ bench "HelloWorld" $ nfIO (writeModule "HelloWorld.bc" =<< readModule "bench/data/HelloWorld.mod")
24+
, bench "HelloWorld2" $ nfIO (writeModule "HelloWorld2.bc" =<< readModule "bench/data/HelloWorld2.mod")
25+
]]

data-bitcode.cabal

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ library
4545
, binary >= 0.8
4646
, base16-bytestring
4747
default-language: Haskell2010
48+
49+
benchmark writer
50+
type: exitcode-stdio-1.0
51+
main-is: Bench.hs
52+
hs-source-dirs:
53+
bench/src
54+
ghc-options: -main-is Bench
55+
build-depends:
56+
base >= 4.7 && < 5
57+
, pretty >= 1.1
58+
, bytestring >= 0.10
59+
, binary >= 0.8
60+
, base16-bytestring
61+
, criterion
62+
, data-bitcode
63+
other-modules:
64+
Bench
65+
default-language: Haskell2010

package.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ dependencies:
1818

1919
library:
2020
source-dirs: src
21+
22+
benchmarks:
23+
writer:
24+
dependencies:
25+
- criterion
26+
- data-bitcode
27+
source-dirs: bench/src
28+
main: Bench

src/Data/BitCode.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Data.Maybe (catMaybes)
99
import Data.Bits (FiniteBits, finiteBitSize, countLeadingZeros)
1010

1111
import GHC.Generics (Generic)
12-
import Data.Binary (Binary)
12+
import Data.Binary (Binary, decodeFile)
1313

1414
--- Bit Codes ------------------------------------------------------------------
1515
-- see BitCodes.h (e.g. http://llvm.org/docs/doxygen/html/BitCodes_8h_source.html)

0 commit comments

Comments
 (0)