Skip to content

Instantly share code, notes, and snippets.

@phunehehe
Last active October 2, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phunehehe/74f149b4012bcecf13e4 to your computer and use it in GitHub Desktop.
Save phunehehe/74f149b4012bcecf13e4 to your computer and use it in GitHub Desktop.
benchmarking repmat/useRepmat whnf
time 112.9 ms (111.7 ms .. 113.7 ms)
1.000 R² (1.000 R² .. 1.000 R²)
mean 113.3 ms (112.8 ms .. 113.9 ms)
std dev 724.5 μs (504.6 μs .. 955.7 μs)
variance introduced by outliers: 11% (moderately inflated)
benchmarking repmat/useReplicate whnf
time 101.6 ms (99.19 ms .. 104.0 ms)
0.999 R² (0.996 R² .. 1.000 R²)
mean 99.94 ms (98.58 ms .. 101.3 ms)
std dev 2.217 ms (1.770 ms .. 2.669 ms)
benchmarking repmat/useRpmt whnf
time 156.9 ms (153.5 ms .. 159.9 ms)
1.000 R² (0.999 R² .. 1.000 R²)
mean 163.2 ms (161.1 ms .. 169.5 ms)
std dev 5.030 ms (595.2 μs .. 6.894 ms)
variance introduced by outliers: 12% (moderately inflated)
benchmarking repmat/useRepmat nf
time 110.9 ms (109.7 ms .. 111.9 ms)
1.000 R² (1.000 R² .. 1.000 R²)
mean 111.9 ms (111.3 ms .. 113.0 ms)
std dev 1.157 ms (649.0 μs .. 1.621 ms)
variance introduced by outliers: 11% (moderately inflated)
benchmarking repmat/useReplicate nf
time 88.64 ms (86.80 ms .. 90.15 ms)
0.998 R² (0.991 R² .. 1.000 R²)
mean 88.28 ms (86.82 ms .. 90.10 ms)
std dev 2.786 ms (1.646 ms .. 4.199 ms)
benchmarking repmat/useRpmt nf
time 158.4 ms (155.1 ms .. 161.8 ms)
1.000 R² (0.999 R² .. 1.000 R²)
mean 162.7 ms (161.2 ms .. 167.1 ms)
std dev 3.515 ms (201.9 μs .. 4.844 ms)
variance introduced by outliers: 12% (moderately inflated)
benchmarking repmat/useRepmat whnf
time 47.83 μs (46.27 μs .. 49.97 μs)
0.990 R² (0.985 R² .. 0.997 R²)
mean 49.00 μs (47.74 μs .. 51.02 μs)
std dev 5.013 μs (3.821 μs .. 5.947 μs)
variance introduced by outliers: 84% (severely inflated)
benchmarking repmat/useReplicate whnf
time 13.97 μs (12.96 μs .. 14.82 μs)
0.980 R² (0.975 R² .. 0.991 R²)
mean 14.13 μs (13.75 μs .. 14.51 μs)
std dev 1.464 μs (1.331 μs .. 1.683 μs)
variance introduced by outliers: 87% (severely inflated)
benchmarking repmat/useRpmt whnf
time 26.06 μs (25.83 μs .. 26.40 μs)
0.999 R² (0.997 R² .. 1.000 R²)
mean 26.08 μs (25.82 μs .. 26.53 μs)
std dev 1.083 μs (656.0 ns .. 1.466 μs)
variance introduced by outliers: 48% (moderately inflated)
benchmarking repmat/useRepmat nf
time 52.68 μs (51.35 μs .. 53.66 μs)
0.996 R² (0.993 R² .. 0.998 R²)
mean 53.65 μs (52.72 μs .. 54.39 μs)
std dev 2.914 μs (2.180 μs .. 3.629 μs)
variance introduced by outliers: 59% (severely inflated)
benchmarking repmat/useReplicate nf
time 13.73 μs (13.14 μs .. 14.66 μs)
0.981 R² (0.977 R² .. 0.987 R²)
mean 15.42 μs (14.75 μs .. 15.88 μs)
std dev 1.736 μs (1.383 μs .. 1.989 μs)
variance introduced by outliers: 88% (severely inflated)
benchmarking repmat/useRpmt nf
time 25.64 μs (25.25 μs .. 26.02 μs)
0.997 R² (0.995 R² .. 0.999 R²)
mean 25.18 μs (24.82 μs .. 25.81 μs)
std dev 1.684 μs (1.384 μs .. 2.042 μs)
variance introduced by outliers: 71% (severely inflated)
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.ST (runST)
import Criterion.Main (bench, bgroup, defaultMain, nf,
whnf)
import Numeric.LinearAlgebra (Container, Matrix, Vector, asRow,
fromList, fromRows, repmat, size)
import Numeric.LinearAlgebra.Devel (MatrixOrder (RowMajor),
newUndefinedMatrix, setMatrix,
unsafeFreezeMatrix)
rpmt :: (Num t, Container Vector t) => Matrix t -> Int -> Int -> Matrix t
rpmt m i j = runST $ do
x <- newUndefinedMatrix RowMajor dr dc
sequence_ [ setMatrix x a b m | a <- [0,r..dr], b <-[0,c..dc] ]
unsafeFreezeMatrix x
where
(r,c) = size m
dr = i*r
dc = j*c
useRepmat :: Vector Double -> Int -> Matrix Double
useRepmat v i = repmat (asRow v) i 1
useReplicate :: Vector Double -> Int -> Matrix Double
useReplicate v i = fromRows $ replicate i v
useRpmt :: Vector Double -> Int -> Matrix Double
useRpmt v i = rpmt (asRow v) i 1
main :: IO ()
main = defaultMain
[ bgroup "repmat"
[ bench "useRepmat whnf" $ whnf (useRepmat v) i
, bench "useReplicate whnf" $ whnf (useReplicate v) i
, bench "useRpmt whnf" $ whnf (useRpmt v) i
, bench "useRepmat nf" $ nf (useRepmat v) i
, bench "useReplicate nf" $ nf (useReplicate v) i
, bench "useRpmt nf" $ nf (useRpmt v) i
]
]
where v = fromList [1..10000]
i = 10000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment