From c55ad7193d3d8d8e89066f898292b6bbf3d8dcfb Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Mon, 22 Jan 2024 10:57:58 +0300 Subject: [PATCH 1/8] Switch to cabal 3.0 This is minimal version that supports public sublibraries. --- vector/vector.cabal | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/vector/vector.cabal b/vector/vector.cabal index be175ef1..d2d3ff99 100644 --- a/vector/vector.cabal +++ b/vector/vector.cabal @@ -1,7 +1,9 @@ +Cabal-Version: 3.0 +Build-Type: Simple Name: vector Version: 0.13.1.0 -- don't forget to update the changelog file! -License: BSD3 +License: BSD-3-Clause License-File: LICENSE Author: Roman Leshchinskiy Maintainer: Haskell Libraries Team @@ -42,26 +44,24 @@ Description: * Tested-With: - GHC == 8.0.2, - GHC == 8.2.2, - 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 == 8.0.2 + GHC == 8.2.2 + 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 == 9.8.1 -Cabal-Version: >= 1.10 -Build-Type: Simple - -Extra-Source-Files: +Extra-doc-files: changelog.md README.md tests/LICENSE +Extra-Source-Files: tests/Setup.hs tests/Main.hs internal/GenUnboxTuple.hs From d10e29b8ba79898206c3876b6d0a995e1cb2ab62 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Mon, 22 Jan 2024 11:14:49 +0300 Subject: [PATCH 2/8] Create public sublibrary for benchmarks suite This exposes benchmarks internal for use with other benchmark tools. In this case for benchmarks based on CPU counters --- vector/{benchmarks => benchmarks-exe}/Main.hs | 0 vector/vector.cabal | 34 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) rename vector/{benchmarks => benchmarks-exe}/Main.hs (100%) diff --git a/vector/benchmarks/Main.hs b/vector/benchmarks-exe/Main.hs similarity index 100% rename from vector/benchmarks/Main.hs rename to vector/benchmarks-exe/Main.hs diff --git a/vector/vector.cabal b/vector/vector.cabal index d2d3ff99..62c2d960 100644 --- a/vector/vector.cabal +++ b/vector/vector.cabal @@ -293,22 +293,16 @@ test-suite vector-inspection , tasty , tasty-inspection-testing >= 0.1 -benchmark algorithms - type: exitcode-stdio-1.0 - main-is: Main.hs +library benchmarks-O2 + visibility: public + ghc-options: -O2 hs-source-dirs: benchmarks - default-language: Haskell2010 - + Default-Language: Haskell2010 build-depends: - base >= 2 && < 5 + base , random >= 1.2 - , tasty - , tasty-bench >= 0.2.1 , vector - - ghc-options: -O2 - - other-modules: + exposed-modules: Algo.MutableSet Algo.ListRank Algo.Rootfix @@ -321,3 +315,19 @@ benchmark algorithms Algo.FindIndexR TestData.ParenTree TestData.Graph + +benchmark algorithms + type: exitcode-stdio-1.0 + main-is: Main.hs + hs-source-dirs: benchmarks-exe + default-language: Haskell2010 + + build-depends: + base >= 2 && < 5 + , random >= 1.2 + , tasty + , tasty-bench >= 0.2.1 + , vector + , vector:benchmarks-O2 + + ghc-options: -O2 From 464e53f597ea2afd20aad5320c57347bd36ae062 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Wed, 24 Jan 2024 21:04:03 +0300 Subject: [PATCH 3/8] We have common stanzas. Let use them --- vector/vector.cabal | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/vector/vector.cabal b/vector/vector.cabal index 62c2d960..670d0377 100644 --- a/vector/vector.cabal +++ b/vector/vector.cabal @@ -89,8 +89,17 @@ Flag Wall Default: False Manual: True +-- This common sets warning flags passed to GHC as controlled by Wall cabal flag +common flag-Wall + Ghc-Options: -Wall + if !flag(Wall) + Ghc-Options: -fno-warn-orphans + if impl(ghc >= 8.0) && impl(ghc < 8.1) + Ghc-Options: -Wno-redundant-constraints + Library + import: flag-Wall Default-Language: Haskell2010 Other-Extensions: BangPatterns @@ -151,13 +160,7 @@ Library , deepseq >= 1.1 && < 1.6 , vector-stream >= 0.1 && < 0.2 - Ghc-Options: -O2 -Wall - - if !flag(Wall) - Ghc-Options: -fno-warn-orphans - - if impl(ghc >= 8.0) && impl(ghc < 8.1) - Ghc-Options: -Wno-redundant-constraints + Ghc-Options: -O2 if flag(BoundsChecks) cpp-options: -DVECTOR_BOUNDS_CHECKS @@ -175,6 +178,7 @@ source-repository head test-suite vector-tests-O0 + import: flag-Wall Default-Language: Haskell2010 type: exitcode-stdio-1.0 Main-Is: Main.hs @@ -209,15 +213,10 @@ test-suite vector-tests-O0 TemplateHaskell Ghc-Options: -O0 -threaded - Ghc-Options: -Wall - - if !flag(Wall) - Ghc-Options: -fno-warn-orphans -fno-warn-missing-signatures - if impl(ghc >= 8.0) && impl(ghc < 8.1) - Ghc-Options: -Wno-redundant-constraints - + Ghc-Options: -fno-warn-missing-signatures test-suite vector-tests-O2 + import: flag-Wall Default-Language: Haskell2010 type: exitcode-stdio-1.0 Main-Is: Main.hs @@ -251,12 +250,8 @@ test-suite vector-tests-O2 TypeFamilies, TemplateHaskell - Ghc-Options: -Wall - Ghc-Options: -O2 -threaded - if !flag(Wall) - Ghc-Options: -fno-warn-orphans -fno-warn-missing-signatures - if impl(ghc >= 8.0) && impl(ghc < 8.1) - Ghc-Options: -Wno-redundant-constraints + Ghc-Options: -O2 -threaded + Ghc-Options: -fno-warn-missing-signatures test-suite vector-doctest type: exitcode-stdio-1.0 @@ -277,9 +272,9 @@ test-suite vector-doctest , vector -any test-suite vector-inspection + import: flag-Wall type: exitcode-stdio-1.0 hs-source-dirs: tests-inspect - Ghc-Options: -Wall main-is: main.hs default-language: Haskell2010 Other-modules: Inspect From 9e4ca8b89da8639407c8b3646921001cc06ba1c6 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Wed, 24 Jan 2024 21:20:18 +0300 Subject: [PATCH 4/8] Move source repository above library --- vector/vector.cabal | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vector/vector.cabal b/vector/vector.cabal index 670d0377..41a89142 100644 --- a/vector/vector.cabal +++ b/vector/vector.cabal @@ -67,6 +67,11 @@ Extra-Source-Files: internal/GenUnboxTuple.hs internal/unbox-tuple-instances +source-repository head + type: git + location: https://github.com/haskell/vector.git + subdir: vector + Flag BoundsChecks Description: Enable bounds checking Default: True @@ -171,10 +176,6 @@ Library if flag(InternalChecks) cpp-options: -DVECTOR_INTERNAL_CHECKS -source-repository head - type: git - location: https://github.com/haskell/vector.git - subdir: vector test-suite vector-tests-O0 From db25c719a1d73fb998a5ebce1a80ceaeb72ae9c4 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Wed, 24 Jan 2024 21:40:23 +0300 Subject: [PATCH 5/8] Use common stanze for tests suite It turns out turning tests into library is not easy thing to do. So just common stanza is used to factor out common functionality for tests Also drop HUinit dependency, we're using tasty-hunit --- vector/vector.cabal | 103 +++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 64 deletions(-) diff --git a/vector/vector.cabal b/vector/vector.cabal index 41a89142..51856e3c 100644 --- a/vector/vector.cabal +++ b/vector/vector.cabal @@ -55,7 +55,7 @@ Tested-With: GHC == 9.4.6 GHC == 9.6.2 GHC == 9.8.1 - + Extra-doc-files: changelog.md @@ -63,7 +63,6 @@ Extra-doc-files: tests/LICENSE Extra-Source-Files: tests/Setup.hs - tests/Main.hs internal/GenUnboxTuple.hs internal/unbox-tuple-instances @@ -177,31 +176,36 @@ Library cpp-options: -DVECTOR_INTERNAL_CHECKS - -test-suite vector-tests-O0 - import: flag-Wall +-- We want to build test suite in two variants. One built with -O0 +-- and another with -O2 in order to catch bugs caused by invalid +-- rewrite rules +common tests-common Default-Language: Haskell2010 - type: exitcode-stdio-1.0 - Main-Is: Main.hs - - other-modules: Boilerplater - Tests.Bundle - Tests.Move - Tests.Vector - Tests.Vector.Property - Tests.Vector.Boxed - Tests.Vector.Storable - Tests.Vector.Primitive - Tests.Vector.Unboxed - Tests.Vector.UnitTests - Utilities - - hs-source-dirs: tests - Build-Depends: base >= 4.5 && < 5, template-haskell, base-orphans >= 0.6, vector, - primitive, random, - QuickCheck >= 2.9 && < 2.15, HUnit, tasty, - tasty-hunit, tasty-quickcheck, - transformers >= 0.2.0.0 + Ghc-Options: -fno-warn-missing-signatures + hs-source-dirs: tests + Build-Depends: base >= 4.5 && < 5 + , template-haskell + , base-orphans >= 0.6 + , vector + , primitive + , random + , QuickCheck >= 2.9 && < 2.15 + , tasty + , tasty-hunit + , tasty-quickcheck + , transformers >= 0.2.0.0 + Other-Modules: + Boilerplater + Tests.Bundle + Tests.Move + Tests.Vector + Tests.Vector.Property + Tests.Vector.Boxed + Tests.Vector.Storable + Tests.Vector.Primitive + Tests.Vector.Unboxed + Tests.Vector.UnitTests + Utilities default-extensions: CPP, ScopedTypeVariables, @@ -213,46 +217,17 @@ test-suite vector-tests-O0 TypeFamilies, TemplateHaskell - Ghc-Options: -O0 -threaded - Ghc-Options: -fno-warn-missing-signatures +test-suite vector-tests-O0 + import: flag-Wall, tests-common + type: exitcode-stdio-1.0 + Main-Is: Main.hs + Ghc-Options: -O0 -threaded test-suite vector-tests-O2 - import: flag-Wall - Default-Language: Haskell2010 - type: exitcode-stdio-1.0 - Main-Is: Main.hs - - other-modules: Boilerplater - Tests.Bundle - Tests.Move - Tests.Vector - Tests.Vector.Property - Tests.Vector.Boxed - Tests.Vector.Storable - Tests.Vector.Primitive - Tests.Vector.Unboxed - Tests.Vector.UnitTests - Utilities - - hs-source-dirs: tests - Build-Depends: base >= 4.5 && < 5, template-haskell, base-orphans >= 0.6, vector, - primitive, random, - QuickCheck >= 2.9 && < 2.15, HUnit, tasty, - tasty-hunit, tasty-quickcheck, - transformers >= 0.2.0.0 - - default-extensions: CPP, - ScopedTypeVariables, - PatternGuards, - MultiParamTypeClasses, - FlexibleContexts, - RankNTypes, - TypeSynonymInstances, - TypeFamilies, - TemplateHaskell - - Ghc-Options: -O2 -threaded - Ghc-Options: -fno-warn-missing-signatures + import: flag-Wall, tests-common + type: exitcode-stdio-1.0 + Main-Is: Main.hs + Ghc-Options: -O2 -threaded test-suite vector-doctest type: exitcode-stdio-1.0 From f4de91e3354fa8dcd23147e57ce5c7ecbdb4ff11 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Mon, 29 Jan 2024 22:30:58 +0300 Subject: [PATCH 6/8] Rename modules in benchmarks lib and move back executable --- .../Bench/Vector}/Algo/AwShCC.hs | 2 +- .../Bench/Vector}/Algo/FindIndexR.hs | 2 +- .../Bench/Vector}/Algo/HybCC.hs | 2 +- .../Bench/Vector}/Algo/Leaffix.hs | 2 +- .../Bench/Vector}/Algo/ListRank.hs | 2 +- .../Bench/Vector}/Algo/MutableSet.hs | 2 +- .../Bench/Vector}/Algo/Quickhull.hs | 2 +- .../Bench/Vector}/Algo/Rootfix.hs | 2 +- .../Bench/Vector}/Algo/Spectral.hs | 2 +- .../Bench/Vector}/Algo/Tridiag.hs | 2 +- .../Bench/Vector}/TestData/Graph.hs | 2 +- .../Bench/Vector}/TestData/ParenTree.hs | 2 +- vector/{benchmarks => benchlib}/README.md | 0 vector/{benchmarks-exe => benchmarks}/Main.hs | 24 ++++++++-------- vector/vector.cabal | 28 +++++++++---------- 15 files changed, 38 insertions(+), 38 deletions(-) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/AwShCC.hs (96%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/FindIndexR.hs (90%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/HybCC.hs (96%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/Leaffix.hs (91%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/ListRank.hs (93%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/MutableSet.hs (95%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/Quickhull.hs (94%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/Rootfix.hs (91%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/Spectral.hs (88%) rename vector/{benchmarks => benchlib/Bench/Vector}/Algo/Tridiag.hs (90%) rename vector/{benchmarks => benchlib/Bench/Vector}/TestData/Graph.hs (96%) rename vector/{benchmarks => benchlib/Bench/Vector}/TestData/ParenTree.hs (93%) rename vector/{benchmarks => benchlib}/README.md (100%) rename vector/{benchmarks-exe => benchmarks}/Main.hs (80%) diff --git a/vector/benchmarks/Algo/AwShCC.hs b/vector/benchlib/Bench/Vector/Algo/AwShCC.hs similarity index 96% rename from vector/benchmarks/Algo/AwShCC.hs rename to vector/benchlib/Bench/Vector/Algo/AwShCC.hs index 404e289f..9f61ca74 100644 --- a/vector/benchmarks/Algo/AwShCC.hs +++ b/vector/benchlib/Bench/Vector/Algo/AwShCC.hs @@ -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 diff --git a/vector/benchmarks/Algo/FindIndexR.hs b/vector/benchlib/Bench/Vector/Algo/FindIndexR.hs similarity index 90% rename from vector/benchmarks/Algo/FindIndexR.hs rename to vector/benchlib/Bench/Vector/Algo/FindIndexR.hs index c7417a24..b77d31e1 100644 --- a/vector/benchmarks/Algo/FindIndexR.hs +++ b/vector/benchlib/Bench/Vector/Algo/FindIndexR.hs @@ -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) diff --git a/vector/benchmarks/Algo/HybCC.hs b/vector/benchlib/Bench/Vector/Algo/HybCC.hs similarity index 96% rename from vector/benchmarks/Algo/HybCC.hs rename to vector/benchlib/Bench/Vector/Algo/HybCC.hs index 876d08f7..db3345d5 100644 --- a/vector/benchmarks/Algo/HybCC.hs +++ b/vector/benchlib/Bench/Vector/Algo/HybCC.hs @@ -1,4 +1,4 @@ -module Algo.HybCC (hybcc) where +module Bench.Vector.Algo.HybCC (hybcc) where import Data.Vector.Unboxed as V diff --git a/vector/benchmarks/Algo/Leaffix.hs b/vector/benchlib/Bench/Vector/Algo/Leaffix.hs similarity index 91% rename from vector/benchmarks/Algo/Leaffix.hs rename to vector/benchlib/Bench/Vector/Algo/Leaffix.hs index 40ec5175..e341daed 100644 --- a/vector/benchmarks/Algo/Leaffix.hs +++ b/vector/benchlib/Bench/Vector/Algo/Leaffix.hs @@ -1,4 +1,4 @@ -module Algo.Leaffix where +module Bench.Vector.Algo.Leaffix where import Data.Vector.Unboxed as V diff --git a/vector/benchmarks/Algo/ListRank.hs b/vector/benchlib/Bench/Vector/Algo/ListRank.hs similarity index 93% rename from vector/benchmarks/Algo/ListRank.hs rename to vector/benchlib/Bench/Vector/Algo/ListRank.hs index 933bd8eb..7c7377d9 100644 --- a/vector/benchmarks/Algo/ListRank.hs +++ b/vector/benchlib/Bench/Vector/Algo/ListRank.hs @@ -1,4 +1,4 @@ -module Algo.ListRank +module Bench.Vector.Algo.ListRank where import Data.Vector.Unboxed as V diff --git a/vector/benchmarks/Algo/MutableSet.hs b/vector/benchlib/Bench/Vector/Algo/MutableSet.hs similarity index 95% rename from vector/benchmarks/Algo/MutableSet.hs rename to vector/benchlib/Bench/Vector/Algo/MutableSet.hs index 12f5e501..8dd187f0 100644 --- a/vector/benchmarks/Algo/MutableSet.hs +++ b/vector/benchlib/Bench/Vector/Algo/MutableSet.hs @@ -1,6 +1,6 @@ {-# LANGUAGE BangPatterns #-} -module Algo.MutableSet +module Bench.Vector.Algo.MutableSet where import Prelude hiding(length, read) diff --git a/vector/benchmarks/Algo/Quickhull.hs b/vector/benchlib/Bench/Vector/Algo/Quickhull.hs similarity index 94% rename from vector/benchmarks/Algo/Quickhull.hs rename to vector/benchlib/Bench/Vector/Algo/Quickhull.hs index 694bea30..da866e27 100644 --- a/vector/benchmarks/Algo/Quickhull.hs +++ b/vector/benchlib/Bench/Vector/Algo/Quickhull.hs @@ -1,4 +1,4 @@ -module Algo.Quickhull (quickhull) where +module Bench.Vector.Algo.Quickhull (quickhull) where import Data.Vector.Unboxed as V diff --git a/vector/benchmarks/Algo/Rootfix.hs b/vector/benchlib/Bench/Vector/Algo/Rootfix.hs similarity index 91% rename from vector/benchmarks/Algo/Rootfix.hs rename to vector/benchlib/Bench/Vector/Algo/Rootfix.hs index 1b112a80..6de8daba 100644 --- a/vector/benchmarks/Algo/Rootfix.hs +++ b/vector/benchlib/Bench/Vector/Algo/Rootfix.hs @@ -1,4 +1,4 @@ -module Algo.Rootfix where +module Bench.Vector.Algo.Rootfix where import Data.Vector.Unboxed as V diff --git a/vector/benchmarks/Algo/Spectral.hs b/vector/benchlib/Bench/Vector/Algo/Spectral.hs similarity index 88% rename from vector/benchmarks/Algo/Spectral.hs rename to vector/benchlib/Bench/Vector/Algo/Spectral.hs index 811c5826..b8ff62fe 100644 --- a/vector/benchmarks/Algo/Spectral.hs +++ b/vector/benchlib/Bench/Vector/Algo/Spectral.hs @@ -1,4 +1,4 @@ -module Algo.Spectral ( spectral ) where +module Bench.Vector.Algo.Spectral ( spectral ) where import Data.Vector.Unboxed as V diff --git a/vector/benchmarks/Algo/Tridiag.hs b/vector/benchlib/Bench/Vector/Algo/Tridiag.hs similarity index 90% rename from vector/benchmarks/Algo/Tridiag.hs rename to vector/benchlib/Bench/Vector/Algo/Tridiag.hs index 7668deac..f28dad52 100644 --- a/vector/benchmarks/Algo/Tridiag.hs +++ b/vector/benchlib/Bench/Vector/Algo/Tridiag.hs @@ -1,4 +1,4 @@ -module Algo.Tridiag ( tridiag ) where +module Bench.Vector.Algo.Tridiag ( tridiag ) where import Data.Vector.Unboxed as V diff --git a/vector/benchmarks/TestData/Graph.hs b/vector/benchlib/Bench/Vector/TestData/Graph.hs similarity index 96% rename from vector/benchmarks/TestData/Graph.hs rename to vector/benchlib/Bench/Vector/TestData/Graph.hs index 81c1ac2f..0643578d 100644 --- a/vector/benchmarks/TestData/Graph.hs +++ b/vector/benchlib/Bench/Vector/TestData/Graph.hs @@ -1,4 +1,4 @@ -module TestData.Graph +module Bench.Vector.TestData.Graph ( randomGraph ) where diff --git a/vector/benchmarks/TestData/ParenTree.hs b/vector/benchlib/Bench/Vector/TestData/ParenTree.hs similarity index 93% rename from vector/benchmarks/TestData/ParenTree.hs rename to vector/benchlib/Bench/Vector/TestData/ParenTree.hs index 4aeb7509..cb9f50a5 100644 --- a/vector/benchmarks/TestData/ParenTree.hs +++ b/vector/benchlib/Bench/Vector/TestData/ParenTree.hs @@ -1,4 +1,4 @@ -module TestData.ParenTree where +module Bench.Vector.TestData.ParenTree where import qualified Data.Vector.Unboxed as V diff --git a/vector/benchmarks/README.md b/vector/benchlib/README.md similarity index 100% rename from vector/benchmarks/README.md rename to vector/benchlib/README.md diff --git a/vector/benchmarks-exe/Main.hs b/vector/benchmarks/Main.hs similarity index 80% rename from vector/benchmarks-exe/Main.hs rename to vector/benchmarks/Main.hs index d6ae78f0..8475ea05 100644 --- a/vector/benchmarks-exe/Main.hs +++ b/vector/benchmarks/Main.hs @@ -1,18 +1,18 @@ 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 Data.Proxy import qualified Data.Vector.Mutable as MV diff --git a/vector/vector.cabal b/vector/vector.cabal index 51856e3c..91cf467d 100644 --- a/vector/vector.cabal +++ b/vector/vector.cabal @@ -267,30 +267,30 @@ test-suite vector-inspection library benchmarks-O2 visibility: public ghc-options: -O2 - hs-source-dirs: benchmarks + hs-source-dirs: benchlib Default-Language: Haskell2010 build-depends: base , random >= 1.2 , vector exposed-modules: - Algo.MutableSet - Algo.ListRank - Algo.Rootfix - Algo.Leaffix - Algo.AwShCC - Algo.HybCC - Algo.Quickhull - Algo.Spectral - Algo.Tridiag - Algo.FindIndexR - TestData.ParenTree - TestData.Graph + Bench.Vector.Algo.MutableSet + Bench.Vector.Algo.ListRank + Bench.Vector.Algo.Rootfix + Bench.Vector.Algo.Leaffix + Bench.Vector.Algo.AwShCC + Bench.Vector.Algo.HybCC + Bench.Vector.Algo.Quickhull + Bench.Vector.Algo.Spectral + Bench.Vector.Algo.Tridiag + Bench.Vector.Algo.FindIndexR + Bench.Vector.TestData.ParenTree + Bench.Vector.TestData.Graph benchmark algorithms type: exitcode-stdio-1.0 main-is: Main.hs - hs-source-dirs: benchmarks-exe + hs-source-dirs: benchmarks default-language: Haskell2010 build-depends: From 26b57e2ed6906bbaaeda0aaeef75cecd8beca252 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Mon, 29 Jan 2024 22:38:41 +0300 Subject: [PATCH 7/8] Move tasty options to library They are used by PAPI based benchmarks as well --- vector/benchlib/Bench/Vector/Tasty.hs | 27 +++++++++++++++++++++++++++ vector/benchmarks/Main.hs | 16 +--------------- vector/vector.cabal | 2 ++ 3 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 vector/benchlib/Bench/Vector/Tasty.hs diff --git a/vector/benchlib/Bench/Vector/Tasty.hs b/vector/benchlib/Bench/Vector/Tasty.hs new file mode 100644 index 00000000..0af8cf6f --- /dev/null +++ b/vector/benchlib/Bench/Vector/Tasty.hs @@ -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" diff --git a/vector/benchmarks/Main.hs b/vector/benchmarks/Main.hs index 8475ea05..e37486a6 100644 --- a/vector/benchmarks/Main.hs +++ b/vector/benchmarks/Main.hs @@ -13,6 +13,7 @@ import Bench.Vector.Algo.FindIndexR (findIndexR, findIndexR_naive, findIndexR_ma 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 @@ -24,21 +25,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 diff --git a/vector/vector.cabal b/vector/vector.cabal index 91cf467d..79ca5bbc 100644 --- a/vector/vector.cabal +++ b/vector/vector.cabal @@ -272,6 +272,7 @@ library benchmarks-O2 build-depends: base , random >= 1.2 + , tasty , vector exposed-modules: Bench.Vector.Algo.MutableSet @@ -286,6 +287,7 @@ library benchmarks-O2 Bench.Vector.Algo.FindIndexR Bench.Vector.TestData.ParenTree Bench.Vector.TestData.Graph + Bench.Vector.Tasty benchmark algorithms type: exitcode-stdio-1.0 From 8fb5d1720c6770025a1b3b74451bb857632aec32 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Mon, 8 Nov 2021 10:38:47 +0300 Subject: [PATCH 8/8] Use bangs in benchmarks. This is: a) Much more readable b) harder to forget to force something --- vector/benchmarks/Main.hs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/vector/benchmarks/Main.hs b/vector/benchmarks/Main.hs index e37486a6..26645cf0 100644 --- a/vector/benchmarks/Main.hs +++ b/vector/benchmarks/Main.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE BangPatterns #-} module Main where import Bench.Vector.Algo.MutableSet (mutableSet) @@ -39,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"