Add a criterion benchmark

This commit is contained in:
Daniel Gröber 2016-07-18 01:09:32 +02:00
parent d92eecbc90
commit c0732ad9cb
5 changed files with 77 additions and 0 deletions

29
bench/Bench.hs Normal file
View File

@ -0,0 +1,29 @@
import Criterion.Main
import Language.Haskell.GhcMod.Target
import TestUtils
import Dir
import System.IO.Temp
import System.Process hiding (env)
import Control.Monad
main = defaultMain [
env setup $ \dir -> bgroup "simple-cabal" [
bench "nop" $ whnfIO (simpleCabalNop dir 1)
, bench "nop10" $ whnfIO (simpleCabalNop dir 10)
]
]
setup = do
tdir <- createTempDirectory "/tmp" "ghc-mod-bench"
system $ "cp -rv \"bench/data/simple-cabal/\" \""++ tdir ++"\""
simpleCabalNop tdir 1 -- warmup dist/
return tdir
simpleCabalNop :: FilePath -> Int -> IO ()
simpleCabalNop dir n = withDirectory_ (dir </> "simple-cabal") $ do
_ <- runGhcModT defaultOptions $
forM_ [1..n] $ \_ -> do
runGmlT [Left "Main.hs"] (return ())
return ()

View File

@ -0,0 +1,4 @@
module Main where
main :: IO ()
main = putStrLn "Hello, Haskell!"

View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View File

@ -0,0 +1,13 @@
name: simple-cabal
version: 0.1.0.0
license: BSD3
license-file: LICENSE
author: Daniel Gröber
maintainer: dxld@darkboxed.org
build-type: Simple
cabal-version: >=1.10
executable simple-cabal
main-is: Main.hs
build-depends: base
default-language: Haskell2010

View File

@ -94,6 +94,8 @@ Extra-Source-Files: ChangeLog
test/data/stack-project/app/*.hs
test/data/stack-project/src/*.hs
test/data/stack-project/test/*.hs
bench/data/simple-cabal/simple-cabal.cabal
bench/data/simple-cabal/*.hs
Custom-Setup
Setup-Depends: base
@ -294,6 +296,33 @@ Test-Suite spec
Build-Depends: hspec >= 2.0.0
X-Build-Depends-Like: CLibName
Benchmark criterion
Type: exitcode-stdio-1.0
Default-Language: Haskell2010
Default-Extensions: ScopedTypeVariables, RecordWildCards, NamedFieldPuns,
ConstraintKinds, FlexibleContexts,
DataKinds, KindSignatures, TypeOperators, ViewPatterns
HS-Source-Dirs: bench, test
Main-Is: Bench.hs
Build-Depends: base
, directory < 1.3
, filepath < 1.5
, pretty < 1.2
, process < 1.5
, split < 0.3
, mtl < 2.3 && >= 2.0
, ghc < 8.1
, monad-journal < 0.8 && >= 0.4
, fclabels == 2.0.*
, temporary < 1.3
, hspec >= 2.0.0
, criterion
, ghc-mod
Source-Repository head
Type: git
Location: https://github.com/DanielG/ghc-mod.git