Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
Add a criterion benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielG committed Jul 18, 2016
1 parent d92eecb commit c0732ad
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bench/Bench.hs
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions bench/data/simple-cabal/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "Hello, Haskell!"
2 changes: 2 additions & 0 deletions bench/data/simple-cabal/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
13 changes: 13 additions & 0 deletions bench/data/simple-cabal/simple-cabal.cabal
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions ghc-mod.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit c0732ad

Please sign in to comment.