Skip to content

Commit

Permalink
Merge pull request #79 from Shimuuar/papi
Browse files Browse the repository at this point in the history
Add PAPI based benchmnarks
  • Loading branch information
Shimuuar committed Apr 8, 2024
2 parents 0e3634c + 6a92a56 commit eeab264
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 18 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -74,6 +74,12 @@ jobs:
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}--${{ github.Shah }}
# ----------------
- name: "Install PAPI"
run: |
sudo apt-get install -y libpapi-dev
echo FLAG_PAPI=-fBenchPAPI >> "$GITHUB_ENV"
if: matrix.os == 'ubuntu-latest'
# ----------------
- name: Versions
run: |
cabal -V
Expand All @@ -97,7 +103,7 @@ jobs:
run: |
if [ "${{ matrix.skip-test }}" == "" ]; then FLAG_TEST=--enable-test; fi
if [ "${{ matrix.skip-bench }}" == "" ]; then FLAG_BENCH=--enable-benchmarks; fi
cabal configure $FLAG_TEST $FLAG_BENCH --flags='${{matrix.flags}}'
cabal configure $FLAG_PAPI $FLAG_TEST $FLAG_BENCH --flags='${{matrix.flags}}'
cabal build all --write-ghc-environment-files=always
# ----------------
- name: Test
Expand Down
11 changes: 11 additions & 0 deletions bench-papi/Bench.hs
@@ -0,0 +1,11 @@
-- |
-- Here we reexport definitions of tasty-papi
module Bench
( whnf
, nf
, bench
, bgroup
, defaultMain
) where

import Test.Tasty.PAPI
11 changes: 11 additions & 0 deletions bench-time/Bench.hs
@@ -0,0 +1,11 @@
-- |
-- Here we reexport definitions of tasty-bench
module Bench
( whnf
, nf
, bench
, bgroup
, defaultMain
) where

import Test.Tasty.Bench
5 changes: 3 additions & 2 deletions bench/bench.hs → bench/main.hs
Expand Up @@ -2,18 +2,19 @@
import Data.Default.Class
import qualified Data.Vector.Unboxed as U
import Text.Printf
import Test.Tasty.Bench
import Test.Tasty (TestTree)
import System.Random (randomIO)

import qualified Numeric.Sum as Sum
import Numeric.SpecFunctions
import Numeric.Polynomial
import Numeric.RootFinding

import Bench


-- Uniformly sample logGamma performance between 10^-6 to 10^6
benchmarkLogGamma :: (Double -> Double) -> [Benchmark]
benchmarkLogGamma :: (Double -> Double) -> [TestTree]
benchmarkLogGamma logG =
[ bench (printf "%.3g" x) $ nf logG x
| x <- [ m * 10**n | n <- [ -8 .. 8 ]
Expand Down
56 changes: 41 additions & 15 deletions math-functions.cabal
@@ -1,15 +1,16 @@
cabal-version: 3.0
build-type: Simple
name: math-functions
version: 0.3.4.4
cabal-version: >= 1.10
license: BSD2
license: BSD-2-Clause
license-file: LICENSE

author: Bryan O'Sullivan <bos@serpentine.com>,
Alexey Khudyakov <alexey.skladnoy@gmail.com>
maintainer: Alexey Khudyakov <alexey.skladnoy@gmail.com>
homepage: https://github.com/haskell/math-functions
bug-reports: https://github.com/haskell/math-functions/issues
category: Math, Numeric
build-type: Simple
synopsis: Collection of tools for numeric computations
description:

Expand All @@ -31,7 +32,6 @@ tested-with:
|| ==9.4.5
|| ==9.6.2


extra-source-files:
changelog.md
README.markdown
Expand All @@ -42,6 +42,10 @@ extra-source-files:
tests/tables/inputs/*.dat
doc/sinc.hs

source-repository head
type: git
location: https://github.com/bos/math-functions

flag system-expm1
description: Use expm1 provided by GHC. On GHCJS we don't have one so we
have to use hand-coded one.
Expand All @@ -55,6 +59,12 @@ flag system-erf
default: True
manual: True

flag BenchPAPI
Description: Enable building of benchmarks which use instruction counters.
It requires libpapi and only works on Linux so it's protected by flag
Default: False
Manual: True

library
default-language: Haskell2010
other-extensions:
Expand Down Expand Up @@ -125,10 +135,13 @@ test-suite math-function-tests
, tasty-hunit >= 0.10
, tasty-quickcheck >= 0.10

benchmark math-functions-bench
type: exitcode-stdio-1.0
if impl(ghcjs)
buildable: False

-- We want to be able to build benchmarks using both tasty-bench and tasty-papi.
-- They have similar API so we just create two shim modules which reexport
-- definitions from corresponding library and pick one in cabal file.

common bench-stanza
ghc-options: -Wall -O2
default-language: Haskell2010
other-extensions:
BangPatterns
Expand All @@ -140,16 +153,29 @@ benchmark math-functions-bench
TemplateHaskell
TypeFamilies
DeriveGeneric
ghc-options: -Wall -O2
hs-source-dirs: bench
Main-is: bench.hs
build-depends: base >= 4.5 && < 5
, math-functions
, data-default-class
, vector
, random
, tasty-bench >=0.3.4
, tasty

source-repository head
type: git
location: https://github.com/bos/math-functions
benchmark math-functions-bench
import: bench-stanza
type: exitcode-stdio-1.0
if impl(ghcjs)
buildable: False
Main-is: main.hs
Other-modules: Bench
hs-source-dirs: bench bench-time
build-depends: tasty-bench >=0.3.4

benchmark math-functions-papi
import: bench-stanza
type: exitcode-stdio-1.0
if impl(ghcjs) || !flag(BenchPAPI) || impl(ghc < 8.2)
buildable: False
Main-is: main.hs
Other-modules: Bench
hs-source-dirs: bench bench-papi
build-depends: tasty-papi >=0.1.2

0 comments on commit eeab264

Please sign in to comment.