Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose tests and benchmarks as public sublibrary #481

Merged
merged 8 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# OPTIONS -fno-spec-constr-count #-}
module Algo.AwShCC (awshcc) where
module Bench.Vector.Algo.AwShCC (awshcc) where

import Data.Vector.Unboxed as V

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Algo.FindIndexR (findIndexR, findIndexR_naive, findIndexR_manual)
module Bench.Vector.Algo.FindIndexR (findIndexR, findIndexR_naive, findIndexR_manual)
where

import Data.Vector.Unboxed (Vector)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Algo.HybCC (hybcc) where
module Bench.Vector.Algo.HybCC (hybcc) where

import Data.Vector.Unboxed as V

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Algo.Leaffix where
module Bench.Vector.Algo.Leaffix where

import Data.Vector.Unboxed as V

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Algo.ListRank
module Bench.Vector.Algo.ListRank
where

import Data.Vector.Unboxed as V
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE BangPatterns #-}

module Algo.MutableSet
module Bench.Vector.Algo.MutableSet
where

import Prelude hiding(length, read)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Algo.Quickhull (quickhull) where
module Bench.Vector.Algo.Quickhull (quickhull) where

import Data.Vector.Unboxed as V

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Algo.Rootfix where
module Bench.Vector.Algo.Rootfix where

import Data.Vector.Unboxed as V

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Algo.Spectral ( spectral ) where
module Bench.Vector.Algo.Spectral ( spectral ) where

import Data.Vector.Unboxed as V

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Algo.Tridiag ( tridiag ) where
module Bench.Vector.Algo.Tridiag ( tridiag ) where

import Data.Vector.Unboxed as V

Expand Down
27 changes: 27 additions & 0 deletions vector/benchlib/Bench/Vector/Tasty.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- |
-- Tasty integration for vector benchmarks.
module Bench.Vector.Tasty
( VectorSize(..)
, RandomSeed(..)
) where

import Test.Tasty.Options


-- | Size of vector used in benchmarks
newtype VectorSize = VectorSize Int

instance IsOption VectorSize where
defaultValue = VectorSize 2000000
parseValue = fmap VectorSize . safeRead
optionName = pure "size"
optionHelp = pure "Size of vectors used in benchmarks"

-- | Random seed used for generation of the test data
newtype RandomSeed = RandomSeed Int

instance IsOption RandomSeed where
defaultValue = RandomSeed 42
parseValue = fmap RandomSeed . safeRead
optionName = pure "seed"
optionHelp = pure "Random seed used for generation of the test data"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module TestData.Graph
module Bench.Vector.TestData.Graph
( randomGraph
) where

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module TestData.ParenTree where
module Bench.Vector.TestData.ParenTree where

import qualified Data.Vector.Unboxed as V

Expand Down
File renamed without changes.
58 changes: 21 additions & 37 deletions vector/benchmarks/Main.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{-# LANGUAGE BangPatterns #-}
module Main where

import Algo.MutableSet (mutableSet)
import Algo.ListRank (listRank)
import Algo.Rootfix (rootfix)
import Algo.Leaffix (leaffix)
import Algo.AwShCC (awshcc)
import Algo.HybCC (hybcc)
import Algo.Quickhull (quickhull)
import Algo.Spectral (spectral)
import Algo.Tridiag (tridiag)
import Algo.FindIndexR (findIndexR, findIndexR_naive, findIndexR_manual)
import Bench.Vector.Algo.MutableSet (mutableSet)
import Bench.Vector.Algo.ListRank (listRank)
import Bench.Vector.Algo.Rootfix (rootfix)
import Bench.Vector.Algo.Leaffix (leaffix)
import Bench.Vector.Algo.AwShCC (awshcc)
import Bench.Vector.Algo.HybCC (hybcc)
import Bench.Vector.Algo.Quickhull (quickhull)
import Bench.Vector.Algo.Spectral (spectral)
import Bench.Vector.Algo.Tridiag (tridiag)
import Bench.Vector.Algo.FindIndexR (findIndexR, findIndexR_naive, findIndexR_manual)

import TestData.ParenTree (parenTree)
import TestData.Graph (randomGraph)
import Bench.Vector.TestData.ParenTree (parenTree)
import Bench.Vector.TestData.Graph (randomGraph)
import Bench.Vector.Tasty

import Data.Proxy
import qualified Data.Vector.Mutable as MV
Expand All @@ -24,21 +26,6 @@ import Test.Tasty.Bench
import Test.Tasty.Options
import Test.Tasty.Runners

newtype VectorSize = VectorSize Int

instance IsOption VectorSize where
defaultValue = VectorSize 2000000
parseValue = fmap VectorSize . safeRead
optionName = pure "size"
optionHelp = pure "Size of vectors used in benchmarks"

newtype RandomSeed = RandomSeed Int

instance IsOption RandomSeed where
defaultValue = RandomSeed 42
parseValue = fmap RandomSeed . safeRead
optionName = pure "seed"
optionHelp = pure "Random seed used in benchmarks"

indexFindThreshold :: Double
indexFindThreshold = 2e-5
Expand All @@ -53,18 +40,15 @@ main = do

gen <- newIOGenM (mkStdGen useSeed)

let (lparens, rparens) = parenTree useSize
(nodes, edges1, edges2) <- randomGraph gen useSize
lparens `seq` rparens `seq` nodes `seq` edges1 `seq` edges2 `seq` return ()
let (!lparens, !rparens) = parenTree useSize
(!nodes, !edges1, !edges2) <- randomGraph gen useSize

let randomVector l = U.replicateM l (uniformDoublePositive01M gen)
as <- randomVector useSize
bs <- randomVector useSize
cs <- randomVector useSize
ds <- randomVector useSize
sp <- randomVector (floor $ sqrt $ fromIntegral useSize)
as `seq` bs `seq` cs `seq` ds `seq` sp `seq` return ()

!as <- randomVector useSize
!bs <- randomVector useSize
!cs <- randomVector useSize
!ds <- randomVector useSize
!sp <- randomVector (floor $ sqrt $ fromIntegral useSize)
vi <- MV.new useSize

defaultMainWithIngredients ingredients $ bgroup "All"
Expand Down
Loading
Loading