Add a criterion benchmark
This commit is contained in:
parent
d92eecbc90
commit
c0732ad9cb
29
bench/Bench.hs
Normal file
29
bench/Bench.hs
Normal 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 ()
|
4
bench/data/simple-cabal/Main.hs
Normal file
4
bench/data/simple-cabal/Main.hs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module Main where
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = putStrLn "Hello, Haskell!"
|
2
bench/data/simple-cabal/Setup.hs
Normal file
2
bench/data/simple-cabal/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import Distribution.Simple
|
||||||
|
main = defaultMain
|
13
bench/data/simple-cabal/simple-cabal.cabal
Normal file
13
bench/data/simple-cabal/simple-cabal.cabal
Normal 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
|
@ -94,6 +94,8 @@ Extra-Source-Files: ChangeLog
|
|||||||
test/data/stack-project/app/*.hs
|
test/data/stack-project/app/*.hs
|
||||||
test/data/stack-project/src/*.hs
|
test/data/stack-project/src/*.hs
|
||||||
test/data/stack-project/test/*.hs
|
test/data/stack-project/test/*.hs
|
||||||
|
bench/data/simple-cabal/simple-cabal.cabal
|
||||||
|
bench/data/simple-cabal/*.hs
|
||||||
|
|
||||||
Custom-Setup
|
Custom-Setup
|
||||||
Setup-Depends: base
|
Setup-Depends: base
|
||||||
@ -294,6 +296,33 @@ Test-Suite spec
|
|||||||
Build-Depends: hspec >= 2.0.0
|
Build-Depends: hspec >= 2.0.0
|
||||||
X-Build-Depends-Like: CLibName
|
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
|
Source-Repository head
|
||||||
Type: git
|
Type: git
|
||||||
Location: https://github.com/DanielG/ghc-mod.git
|
Location: https://github.com/DanielG/ghc-mod.git
|
||||||
|
Loading…
Reference in New Issue
Block a user