Skip to content

Commit 0981497

Browse files
committed
Add PAPI-based benchmarks
Since they are require libpapi and only works on linux they're protected by cabal flag and have to be enabled explicitly PAPI benchmark couldn't be built on GHC 8.0
1 parent 85297ff commit 0981497

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

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)