Skip to content

Commit 197eeb4

Browse files
authored
Merge pull request #426 from haskell/bench-papi
Benchmarks based on CPU counters
2 parents 85297ff + c7d8173 commit 197eeb4

File tree

4 files changed

+131
-4
lines changed

4 files changed

+131
-4
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ jobs:
6969
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
7070
key: ${{ runner.os }}-${{ matrix.ghc }}--${{ github.Shah }}-CACHE_V3
7171
# ----------------
72+
- name: "Install PAPI"
73+
run: |
74+
sudo apt-get install -y libpapi-dev
75+
echo FLAG_PAPI=-fBenchPAPI >> "$GITHUB_ENV"
76+
if: matrix.os == 'ubuntu-latest'
77+
# ----------------
7278
- name: Versions
7379
run: |
7480
cabal -V
@@ -86,13 +92,13 @@ jobs:
8692
# ----------------
8793
- name: cabal check
8894
run: |
89-
cd vector
90-
cabal -vnormal check
95+
(cd vector-stream && cabal -vnormal check)
96+
(cd vector && cabal -vnormal check)
9197
# ----------------
9298
- name: Build
9399
run: |
94-
set -x
95-
cabal configure ${{ matrix.flags }} --haddock-all --enable-tests --enable-benchmarks --benchmark-option=-l
100+
echo FLAG_PAPI=$FLAG_PAPI
101+
cabal configure ${{ matrix.flags }} $FLAG_PAPI --haddock-all --enable-tests --enable-benchmarks --benchmark-option=-l
96102
cabal build all --write-ghc-environment-files=always
97103
# ----------------
98104
- name: Test

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
packages:
22
vector
33
vector-stream
4+
vector-bench-papi
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{-# LANGUAGE BangPatterns #-}
2+
module Main where
3+
4+
import Bench.Vector.Algo.MutableSet (mutableSet)
5+
import Bench.Vector.Algo.ListRank (listRank)
6+
import Bench.Vector.Algo.Rootfix (rootfix)
7+
import Bench.Vector.Algo.Leaffix (leaffix)
8+
import Bench.Vector.Algo.AwShCC (awshcc)
9+
import Bench.Vector.Algo.HybCC (hybcc)
10+
import Bench.Vector.Algo.Quickhull (quickhull)
11+
import Bench.Vector.Algo.Spectral (spectral)
12+
import Bench.Vector.Algo.Tridiag (tridiag)
13+
import Bench.Vector.Algo.FindIndexR (findIndexR, findIndexR_naive, findIndexR_manual)
14+
15+
import Bench.Vector.TestData.ParenTree (parenTree)
16+
import Bench.Vector.TestData.Graph (randomGraph)
17+
import Bench.Vector.Tasty
18+
19+
import Data.Proxy
20+
import qualified Data.Vector.Mutable as MV
21+
import qualified Data.Vector.Unboxed as U
22+
import Data.Word
23+
import System.Random.Stateful
24+
import Test.Tasty
25+
import Test.Tasty.PAPI
26+
import Test.Tasty.Options
27+
import Test.Tasty.Runners
28+
29+
indexFindThreshold :: Double
30+
indexFindThreshold = 2e-5
31+
32+
main :: IO ()
33+
main = do
34+
let ourOpts = [Option (Proxy :: Proxy VectorSize), Option (Proxy :: Proxy RandomSeed)]
35+
ingredients = includingOptions ourOpts : benchIngredients
36+
opts <- parseOptions ingredients (bench "Fake" (nf id ()))
37+
let VectorSize useSize = lookupOption opts
38+
RandomSeed useSeed = lookupOption opts
39+
40+
gen <- newIOGenM (mkStdGen useSeed)
41+
42+
let (!lparens, !rparens) = parenTree useSize
43+
(!nodes, !edges1, !edges2) <- randomGraph gen useSize
44+
45+
let randomVector l = U.replicateM l (uniformDoublePositive01M gen)
46+
!as <- randomVector useSize
47+
!bs <- randomVector useSize
48+
!cs <- randomVector useSize
49+
!ds <- randomVector useSize
50+
!sp <- randomVector (floor $ sqrt $ fromIntegral useSize)
51+
vi <- MV.new useSize
52+
53+
defaultMainWithIngredients ingredients $ bgroup "All"
54+
[ bench "listRank" $ whnf listRank useSize
55+
, bench "rootfix" $ whnf rootfix (lparens, rparens)
56+
, bench "leaffix" $ whnf leaffix (lparens, rparens)
57+
, bench "awshcc" $ whnf awshcc (nodes, edges1, edges2)
58+
, bench "hybcc" $ whnf hybcc (nodes, edges1, edges2)
59+
, bench "quickhull" $ whnf quickhull (as,bs)
60+
, bench "spectral" $ whnf spectral sp
61+
, bench "tridiag" $ whnf tridiag (as,bs,cs,ds)
62+
, bench "mutableSet" $ nfIO $ mutableSet vi
63+
, bench "findIndexR" $ whnf findIndexR ((<indexFindThreshold), as)
64+
, bench "findIndexR_naïve" $ whnf findIndexR_naive ((<indexFindThreshold), as)
65+
, bench "findIndexR_manual" $ whnf findIndexR_manual ((<indexFindThreshold), as)
66+
, bench "minimumOn" $ whnf (U.minimumOn (\x -> x*x*x)) as
67+
, bench "maximumOn" $ whnf (U.maximumOn (\x -> x*x*x)) as
68+
]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Cabal-Version: 3.0
2+
Build-Type: Simple
3+
Name: vector-bench-papi
4+
Version: 0.13.1.0
5+
License: BSD-3-Clause
6+
License-File: LICENSE
7+
8+
Author: Alexey Khudyakov <[email protected]>
9+
Maintainer: Haskell Libraries Team <[email protected]>
10+
Alexey Kuleshevich <[email protected]>,
11+
Aleksey Khudyakov <[email protected]>,
12+
Andrew Lelechenko <[email protected]>
13+
14+
Copyright: (c) Aleksey Khudyakov 2024,
15+
16+
Homepage: https://github.com/haskell/vector
17+
Bug-Reports: https://github.com/haskell/vector/issues
18+
19+
Category: Benchmark
20+
Synopsis: PAPI based benchmarks for vector-package
21+
Description:
22+
Benchmarks for vector package which use CPU counter instead of time measurements.
23+
24+
Note that benchmarks will not be built unless flag -fBenchPAPI is
25+
specified.
26+
27+
Flag BenchPAPI
28+
Description: Enable building of benchmarks which use instruction counters.
29+
It requires libpapi and only works on Linux so it's protected by flag
30+
Default: False
31+
Manual: True
32+
33+
library
34+
default-language: Haskell2010
35+
36+
benchmark algorithms-papi
37+
if !flag(BenchPAPI) || impl(ghc < 8.2)
38+
buildable: False
39+
type: exitcode-stdio-1.0
40+
main-is: Main.hs
41+
hs-source-dirs: benchmarks
42+
default-language: Haskell2010
43+
44+
build-depends:
45+
base >= 2 && < 5
46+
, random >= 1.2
47+
, tasty
48+
, tasty-papi >= 0.1.2.0
49+
, vector
50+
, vector:benchmarks-O2
51+
52+
ghc-options: -O2

0 commit comments

Comments
 (0)