Skip to content

Commit 15a5393

Browse files
treeowlivan-m
authored andcommitted
Add cabal benchmark integration
* Add the benchmarks to `fgl.cabal`. * Disable AVL benchmarks that result in errors. Surely something needs to be fixed! * Add benchmark for building a full graph with `&`. * Enable GHC optimizations. Otherwise, none of the `RULES` or inlining the source code talks about can ever happen. * Disable `cabal check`, which barfs on `-O2`.
1 parent 8f8066b commit 15a5393

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ script:
8989
- cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging
9090
- cabal build # this builds all libraries and executables (including tests/benchmarks)
9191
- cabal test
92-
- cabal check
9392
- cabal sdist # tests that a source-distribution can be generated
9493

9594
# Check that the resulting source distribution can be built & installed.

fgl.cabal

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ library {
7979
build-depends:
8080
ghc-prim
8181

82-
ghc-options: -Wall
82+
ghc-options: -Wall -O2
8383

8484
}
8585

@@ -104,6 +104,24 @@ test-suite fgl-tests {
104104
, Data.Graph.Inductive.Proxy
105105
, Data.Graph.Inductive.Query.Properties
106106

107-
ghc-options: -Wall
107+
ghc-options: -Wall -O2
108+
109+
}
110+
111+
benchmark fgl-benchmark {
112+
default-language: Haskell98
113+
114+
type: exitcode-stdio-1.0
115+
116+
hs-source-dirs: test
117+
118+
main-is: benchmark.hs
119+
120+
build-depends: fgl
121+
, base
122+
, microbench
123+
, deepseq
124+
125+
ghc-options: -Wall -O2
108126

109127
}

test/benchmark.hs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{-
2-
Install microbench to build this program:
2+
This program should generally be run using `cabal bench` or
3+
`stack bench`. To use `stack bench`, edit stack.yaml to include
4+
5+
extra-deps:
6+
- microbench-0.1
7+
8+
To run benchmarks manually, install microbench from
39
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/microbench
410
11+
then run
12+
513
% ghc -O --make benchmark
614
% ./benchmark
715
[1 of 1] Compiling Main ( benchmark.hs, benchmark.o )
@@ -28,17 +36,27 @@
2836
4.532ns per iteration / 220663.09 per second.
2937
-}
3038

39+
{-# LANGUAGE CPP #-}
40+
{-# LANGUAGE ScopedTypeVariables #-}
41+
#if __GLASGOW_HASKELL__ >= 708
42+
3143
import Data.Graph.Inductive.Graph
3244
import qualified Data.Graph.Inductive.Tree as AVL
3345
import qualified Data.Graph.Inductive.PatriciaTree as Patricia
3446
import Microbench
35-
47+
import Data.Foldable (foldl')
48+
import Control.DeepSeq
49+
import Data.Proxy
3650

3751
main :: IO ()
3852
main = do microbench "insNode into AVL tree" insNodeAVL
3953
microbench "insNode into PATRICIA tree" insNodePatricia
4054

41-
microbench "insEdge into AVL tree" insEdgeAVL
55+
microbench "buildFull into PATRICIA tree 100" (buildFullPatricia 100)
56+
microbench "buildFull into PATRICIA tree 500" (buildFullPatricia 500)
57+
microbench "buildFull into PATRICIA tree 1000" (buildFullPatricia 1000)
58+
59+
-- microbench "insEdge into AVL tree" insEdgeAVL
4260
microbench "insEdge into PATRICIA tree" insEdgePatricia
4361

4462
microbench "gmap on AVL tree" gmapAVL
@@ -47,17 +65,27 @@ main = do microbench "insNode into AVL tree" insNodeAVL
4765
microbench "nmap on AVL tree" nmapAVL
4866
microbench "nmap on PATRICIA tree" nmapPatricia
4967

50-
microbench "emap on AVL tree" emapAVL
68+
-- microbench "emap on AVL tree" emapAVL
5169
microbench "emap on PATRICIA tree" emapPatricia
5270

5371

5472
insNodeAVL :: Int -> AVL.UGr
5573
insNodeAVL = insNodes' empty
5674

75+
buildFullPatricia :: Int -> Int -> ()
76+
buildFullPatricia sz i = buildFull (Proxy :: Proxy Patricia.Gr) sz i
5777

5878
insNodePatricia :: Int -> Patricia.UGr
5979
insNodePatricia = insNodes' empty
6080

81+
buildFull :: forall gr proxy . (DynGraph gr, NFData (gr Int ())) => proxy gr -> Int -> Int -> ()
82+
buildFull _ sz ntimes = rnf [buildFull' i (empty :: gr Int ()) 0 sz | i <- [0..ntimes-1]]
83+
84+
buildFull' :: DynGraph gr => a -> gr a () -> Int -> Int -> gr a ()
85+
buildFull' a g n limit
86+
| n == limit = empty
87+
| otherwise = ([((), k) | k <- [0..n-1]],n,a,[((),k) | k <- [0..n-1]]) & buildFull' a g (n + 1) limit
88+
6189

6290
{-# INLINE insNodes' #-}
6391
insNodes' :: DynGraph gr => gr () b -> Int -> gr () b
@@ -135,4 +163,9 @@ emapPatricia n
135163
g' = emap f g
136164
f _ = n
137165
in
138-
g'
166+
g'
167+
168+
#else
169+
main :: IO ()
170+
main = putStrLn "Benchmarks are only supported for GHC 7.8 and above."
171+
#endif

0 commit comments

Comments
 (0)