Skip to content

Commit eeab264

Browse files
authored
Merge pull request #79 from Shimuuar/papi
Add PAPI based benchmnarks
2 parents 0e3634c + 6a92a56 commit eeab264

File tree

5 files changed

+73
-18
lines changed

5 files changed

+73
-18
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ jobs:
7474
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
7575
key: ${{ runner.os }}-${{ matrix.ghc }}--${{ github.Shah }}
7676
# ----------------
77+
- name: "Install PAPI"
78+
run: |
79+
sudo apt-get install -y libpapi-dev
80+
echo FLAG_PAPI=-fBenchPAPI >> "$GITHUB_ENV"
81+
if: matrix.os == 'ubuntu-latest'
82+
# ----------------
7783
- name: Versions
7884
run: |
7985
cabal -V
@@ -97,7 +103,7 @@ jobs:
97103
run: |
98104
if [ "${{ matrix.skip-test }}" == "" ]; then FLAG_TEST=--enable-test; fi
99105
if [ "${{ matrix.skip-bench }}" == "" ]; then FLAG_BENCH=--enable-benchmarks; fi
100-
cabal configure $FLAG_TEST $FLAG_BENCH --flags='${{matrix.flags}}'
106+
cabal configure $FLAG_PAPI $FLAG_TEST $FLAG_BENCH --flags='${{matrix.flags}}'
101107
cabal build all --write-ghc-environment-files=always
102108
# ----------------
103109
- name: Test

bench-papi/Bench.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- |
2+
-- Here we reexport definitions of tasty-papi
3+
module Bench
4+
( whnf
5+
, nf
6+
, bench
7+
, bgroup
8+
, defaultMain
9+
) where
10+
11+
import Test.Tasty.PAPI

bench-time/Bench.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- |
2+
-- Here we reexport definitions of tasty-bench
3+
module Bench
4+
( whnf
5+
, nf
6+
, bench
7+
, bgroup
8+
, defaultMain
9+
) where
10+
11+
import Test.Tasty.Bench

bench/bench.hs renamed to bench/main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
import Data.Default.Class
33
import qualified Data.Vector.Unboxed as U
44
import Text.Printf
5-
import Test.Tasty.Bench
5+
import Test.Tasty (TestTree)
66
import System.Random (randomIO)
77

88
import qualified Numeric.Sum as Sum
99
import Numeric.SpecFunctions
1010
import Numeric.Polynomial
1111
import Numeric.RootFinding
1212

13+
import Bench
1314

1415

1516
-- Uniformly sample logGamma performance between 10^-6 to 10^6
16-
benchmarkLogGamma :: (Double -> Double) -> [Benchmark]
17+
benchmarkLogGamma :: (Double -> Double) -> [TestTree]
1718
benchmarkLogGamma logG =
1819
[ bench (printf "%.3g" x) $ nf logG x
1920
| x <- [ m * 10**n | n <- [ -8 .. 8 ]

math-functions.cabal

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
cabal-version: 3.0
2+
build-type: Simple
13
name: math-functions
24
version: 0.3.4.4
3-
cabal-version: >= 1.10
4-
license: BSD2
5+
license: BSD-2-Clause
56
license-file: LICENSE
7+
68
author: Bryan O'Sullivan <bos@serpentine.com>,
79
Alexey Khudyakov <alexey.skladnoy@gmail.com>
810
maintainer: Alexey Khudyakov <alexey.skladnoy@gmail.com>
911
homepage: https://github.com/haskell/math-functions
1012
bug-reports: https://github.com/haskell/math-functions/issues
1113
category: Math, Numeric
12-
build-type: Simple
1314
synopsis: Collection of tools for numeric computations
1415
description:
1516

@@ -31,7 +32,6 @@ tested-with:
3132
|| ==9.4.5
3233
|| ==9.6.2
3334

34-
3535
extra-source-files:
3636
changelog.md
3737
README.markdown
@@ -42,6 +42,10 @@ extra-source-files:
4242
tests/tables/inputs/*.dat
4343
doc/sinc.hs
4444

45+
source-repository head
46+
type: git
47+
location: https://github.com/bos/math-functions
48+
4549
flag system-expm1
4650
description: Use expm1 provided by GHC. On GHCJS we don't have one so we
4751
have to use hand-coded one.
@@ -55,6 +59,12 @@ flag system-erf
5559
default: True
5660
manual: True
5761

62+
flag BenchPAPI
63+
Description: Enable building of benchmarks which use instruction counters.
64+
It requires libpapi and only works on Linux so it's protected by flag
65+
Default: False
66+
Manual: True
67+
5868
library
5969
default-language: Haskell2010
6070
other-extensions:
@@ -125,10 +135,13 @@ test-suite math-function-tests
125135
, tasty-hunit >= 0.10
126136
, tasty-quickcheck >= 0.10
127137

128-
benchmark math-functions-bench
129-
type: exitcode-stdio-1.0
130-
if impl(ghcjs)
131-
buildable: False
138+
139+
-- We want to be able to build benchmarks using both tasty-bench and tasty-papi.
140+
-- They have similar API so we just create two shim modules which reexport
141+
-- definitions from corresponding library and pick one in cabal file.
142+
143+
common bench-stanza
144+
ghc-options: -Wall -O2
132145
default-language: Haskell2010
133146
other-extensions:
134147
BangPatterns
@@ -140,16 +153,29 @@ benchmark math-functions-bench
140153
TemplateHaskell
141154
TypeFamilies
142155
DeriveGeneric
143-
ghc-options: -Wall -O2
144-
hs-source-dirs: bench
145-
Main-is: bench.hs
146156
build-depends: base >= 4.5 && < 5
147157
, math-functions
148158
, data-default-class
149159
, vector
150160
, random
151-
, tasty-bench >=0.3.4
161+
, tasty
152162

153-
source-repository head
154-
type: git
155-
location: https://github.com/bos/math-functions
163+
benchmark math-functions-bench
164+
import: bench-stanza
165+
type: exitcode-stdio-1.0
166+
if impl(ghcjs)
167+
buildable: False
168+
Main-is: main.hs
169+
Other-modules: Bench
170+
hs-source-dirs: bench bench-time
171+
build-depends: tasty-bench >=0.3.4
172+
173+
benchmark math-functions-papi
174+
import: bench-stanza
175+
type: exitcode-stdio-1.0
176+
if impl(ghcjs) || !flag(BenchPAPI) || impl(ghc < 8.2)
177+
buildable: False
178+
Main-is: main.hs
179+
Other-modules: Bench
180+
hs-source-dirs: bench bench-papi
181+
build-depends: tasty-papi >=0.1.2

0 commit comments

Comments
 (0)