aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <t.j.smeding@uu.nl>2024-06-10 16:17:59 +0200
committerTom Smeding <t.j.smeding@uu.nl>2024-06-10 16:17:59 +0200
commitbb1e1fcd1b0f47747623f1497a4f4ae0f7a2a62d (patch)
tree4c0a2940b9a41d73150336a3937de1567c12b2cf
parent205a20fd581bb7c5728fd457a15e4f78fbee9e75 (diff)
Benchmark dot product
-rw-r--r--bench/Main.hs24
-rw-r--r--ox-arrays.cabal1
2 files changed, 25 insertions, 0 deletions
diff --git a/bench/Main.hs b/bench/Main.hs
index fdb7f25..eb3c6d7 100644
--- a/bench/Main.hs
+++ b/bench/Main.hs
@@ -3,6 +3,7 @@
{-# LANGUAGE TypeApplications #-}
module Main where
+import Data.Array.RankedS qualified as RS
import Numeric.LinearAlgebra qualified as LA
import Test.Tasty.Bench
@@ -64,6 +65,14 @@ main = defaultMain
let n = 1_000_000
in nf (\a -> runScalar (rsumOuter1 a))
(riota @Double n)
+ ,bench "dotprod Double [1e6]" $
+ let n = 1_000_000
+ in nf (\(a, b) -> rdot a b)
+ (riota @Double n, riota @Double n)
+ ,bench "dotprod Double [1e6] stride 1; -1" $
+ let n = 1_000_000
+ in nf (\(a, b) -> rdot a b)
+ (riota @Double n, rrev1 (riota @Double n))
]
,bgroup "hmatrix"
[bench "sum(+) Double [1e6]" $
@@ -94,5 +103,20 @@ main = defaultMain
let n = 1_000_000
in nf (\a -> LA.sumElements a)
(LA.linspace @Double n (0.0, fromIntegral (n - 1)))
+ ,bench "dotprod Double [1e6]" $
+ let n = 1_000_000
+ in nf (\(a, b) -> a LA.<.> b)
+ (LA.linspace @Double n (0.0, fromIntegral (n - 1))
+ ,LA.linspace @Double n (fromIntegral (n - 1), 0.0))
+ ]
+ ,bgroup "orthotope"
+ [bench "normalize [1e6]" $
+ let n = 1_000_000
+ in nf (\a -> RS.normalize a)
+ (RS.rev [0] (RS.iota @Double n))
+ ,bench "normalize noop [1e6]" $
+ let n = 1_000_000
+ in nf (\a -> RS.normalize a)
+ (RS.rev [0] (RS.rev [0] (RS.iota @Double n)))
]
]
diff --git a/ox-arrays.cabal b/ox-arrays.cabal
index 8e4b710..9153336 100644
--- a/ox-arrays.cabal
+++ b/ox-arrays.cabal
@@ -100,6 +100,7 @@ benchmark bench
ox-arrays,
base,
hmatrix,
+ orthotope,
tasty-bench
hs-source-dirs: bench
default-language: Haskell2010