Skip to content

Commit

Permalink
Merge pull request #210 from Shimuuar/CI
Browse files Browse the repository at this point in the history
Update CI and add tasty-bench based benchmarks
  • Loading branch information
Shimuuar authored Jan 14, 2025
2 parents 17ba95f + 713a857 commit d914fa8
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 46 deletions.
32 changes: 20 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: CI
on:
pull_request:
push:
branches: [master, GA]
branches: [master]

defaults:
run:
Expand All @@ -18,33 +18,41 @@ jobs:
matrix:
include:
# Linux
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.4.4" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.6.5" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.8.4" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.10.7" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.0.2" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.2.8" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.4.6" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.6.2" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "8.4.4" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "8.6.5" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "8.8.4" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "8.10.7" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "9.0.2" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "9.2.8" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "9.4.8" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "9.6.6" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "9.8.4" }
- { cabal: "3.12", os: ubuntu-latest, ghc: "9.10.1" }
# Fails to resolve aeson [2025.01.14]
# - { cabal: "3.12", os: ubuntu-latest, ghc: "9.12.1" }
fail-fast: false

steps:
# ----------------
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# ----------------
- uses: haskell/actions/setup@v2
- uses: haskell-actions/setup@v2
id: setup-haskell-cabal
name: Setup Haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
# ----------------
- uses: actions/cache@v1
- uses: actions/cache@v3
name: Cache ~/.cabal/store
with:
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}--${{ github.Shah }}-CACHE_V3
# ----------------
- name: "Install PAPI"
run: |
sudo apt-get install -y libpapi-dev
# ----------------
- name: Versions
run: |
cabal -V
Expand Down
14 changes: 14 additions & 0 deletions bench-papi/Bench.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- |
-- Here we reexport definitions of tasty-bench
module Bench
( whnf
, nf
, nfIO
, whnfIO
, bench
, bgroup
, defaultMain
, benchIngredients
) where

import Test.Tasty.PAPI
14 changes: 14 additions & 0 deletions bench-time/Bench.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- |
-- Here we reexport definitions of tasty-bench
module Bench
( whnf
, nf
, nfIO
, whnfIO
, bench
, bgroup
, defaultMain
, benchIngredients
) where

import Test.Tasty.Bench
38 changes: 19 additions & 19 deletions benchmark/bench.hs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import Control.Monad.ST (runST)
import Criterion.Main
import Data.Complex
import Statistics.Sample
import Statistics.Transform
import Statistics.Correlation.Pearson
import Statistics.Correlation
import System.Random.MWC
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as MVU

import Bench


-- Test sample
sample :: U.Vector Double
sample = runST $ flip uniformVector 10000 =<< create
sample :: VU.Vector Double
sample = VU.create $ do g <- create
MVU.replicateM 10000 (uniform g)

-- Weighted test sample
sampleW :: U.Vector (Double,Double)
sampleW = U.zip sample (U.reverse sample)
sampleW :: VU.Vector (Double,Double)
sampleW = VU.zip sample (VU.reverse sample)

-- Complex vector for FFT tests
sampleC :: U.Vector (Complex Double)
sampleC = U.zipWith (:+) sample (U.reverse sample)
sampleC :: VU.Vector (Complex Double)
sampleC = VU.zipWith (:+) sample (VU.reverse sample)


-- Simple benchmark for functions from Statistics.Sample
Expand All @@ -37,9 +39,7 @@ main =
, bench "varianceUnbiased" $ nf (\x -> varianceUnbiased x) sample
, bench "varianceWeighted" $ nf (\x -> varianceWeighted x) sampleW
-- Correlation
, bench "pearson" $ nf (\x -> pearson (U.reverse sample) x) sample
, bench "pearson'" $ nf (\x -> pearson' (U.reverse sample) x) sample
, bench "pearsonFast" $ nf (\x -> pearsonFast (U.reverse sample) x) sample
, bench "pearson" $ nf pearson sampleW
-- Other
, bench "stdDev" $ nf (\x -> stdDev x) sample
, bench "skewness" $ nf (\x -> skewness x) sample
Expand All @@ -52,17 +52,17 @@ main =
]
, bgroup "FFT"
[ bgroup "fft"
[ bench (show n) $ whnf fft (U.take n sampleC) | n <- fftSizes ]
[ bench (show n) $ whnf fft (VU.take n sampleC) | n <- fftSizes ]
, bgroup "ifft"
[ bench (show n) $ whnf ifft (U.take n sampleC) | n <- fftSizes ]
[ bench (show n) $ whnf ifft (VU.take n sampleC) | n <- fftSizes ]
, bgroup "dct"
[ bench (show n) $ whnf dct (U.take n sample) | n <- fftSizes ]
[ bench (show n) $ whnf dct (VU.take n sample) | n <- fftSizes ]
, bgroup "dct_"
[ bench (show n) $ whnf dct_ (U.take n sampleC) | n <- fftSizes ]
[ bench (show n) $ whnf dct_ (VU.take n sampleC) | n <- fftSizes ]
, bgroup "idct"
[ bench (show n) $ whnf idct (U.take n sample) | n <- fftSizes ]
[ bench (show n) $ whnf idct (VU.take n sample) | n <- fftSizes ]
, bgroup "idct_"
[ bench (show n) $ whnf idct_ (U.take n sampleC) | n <- fftSizes ]
[ bench (show n) $ whnf idct_ (VU.take n sampleC) | n <- fftSizes ]
]
]

Expand Down
68 changes: 53 additions & 15 deletions statistics.cabal
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
cabal-version: 3.0
build-type: Simple

name: statistics
version: 0.16.2.1
synopsis: A library of statistical types, data, and functions
Expand All @@ -22,19 +25,17 @@ description:
* Common statistical tests for significant differences between
samples.

license: BSD2
license: BSD-2-Clause
license-file: LICENSE
homepage: https://github.com/haskell/statistics
bug-reports: https://github.com/haskell/statistics/issues
author: Bryan O'Sullivan <[email protected]>, Alexey Khudaykov <[email protected]>
maintainer: Alexey Khudaykov <[email protected]>
copyright: 2009-2014 Bryan O'Sullivan
category: Math, Statistics
build-type: Simple
cabal-version: >= 1.10

extra-source-files:
README.markdown
benchmark/bench.hs
changelog.md
examples/kde/KDE.hs
examples/kde/data/faithful.csv
Expand All @@ -46,15 +47,26 @@ extra-source-files:
tests/utils/fftw.c

tested-with:
GHC ==8.4.4
GHC ==8.6.5
GHC ==8.8.4
GHC ==8.10.7
GHC ==9.0.2
GHC ==9.2.8
GHC ==9.4.6
GHC ==9.6.2
GHC ==8.4.4
|| ==8.6.5
|| ==8.8.4
|| ==8.10.7
|| ==9.0.2
|| ==9.2.8
|| ==9.4.8
|| ==9.6.6
|| ==9.8.4
|| ==9.10.1

source-repository head
type: git
location: https://github.com/haskell/statistics

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
Expand Down Expand Up @@ -176,6 +188,32 @@ test-suite statistics-tests
, vector
, vector-algorithms

source-repository head
type: git
location: https://github.com/haskell/statistics
-- 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
default-language: Haskell2010
build-depends: base < 5
, vector >= 0.12.3
, statistics
, mwc-random
, tasty >=1.3.1

benchmark statistics-bench
import: bench-stanza
type: exitcode-stdio-1.0
hs-source-dirs: benchmark bench-time
main-is: bench.hs
Other-modules: Bench
build-depends: tasty-bench >= 0.3

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

0 comments on commit d914fa8

Please sign in to comment.