public
Created

  • Download Gist
bench.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
import System.Environment
import Data.Array.Repa as R
import Data.Array.Repa.Algorithms.Randomish as RR
import Criterion.Main
import Criterion.Config
 
ra = RR.randomishDoubleArray (ix2 1000 3) 0 1 1
 
main = defaultMainWith defaultConfig {cfgSamples = ljust 10} (return ()) [
bgroup "pairwise-random" [
bench "extract" $ whnf pairwise ra,
bench "slice" $ whnf pairwise2 ra
]
]
 
pairwise :: Array U DIM2 Double -> Array U DIM2 Double
pairwise in_ =
let Z :. m :. n = extent in_
getRow i = extract (ix2 i 0) (ix2 i n) in_
v i j = (getRow i) -^ (getRow j)
f (Z :. i :. j) = R.sumAllS $ (v i j) *^ (v i j)
arrayD = fromFunction (ix2 m m) f
in computeUnboxedS arrayD
 
pairwise2 :: Array U DIM2 Double -> Array U DIM2 Double
pairwise2 in_ =
let Z :. m :. n = extent in_
getRow i = (slice in_ $ Any :. (i::Int) :. All)
v i j = (getRow i) -^ (getRow j)
f (Z :. i :. j) = R.sumAllS $ (v i j) *^ (v i j)
arrayD = fromFunction (ix2 m m) f
in computeUnboxedS arrayD
 
 
------
$ ghc --make matrix.hs -Odph -rtsopts -threaded -fno-liberate-case -funfolding-use-threshold1000 -funfolding-keeness-factor1000 -fllvm -optlo-O3
[1 of 1] Compiling Main ( matrix.hs, matrix.o )
Linking matrix ...
 
$ ./matrix
warming up
estimating clock resolution...
mean is 1.654411 us (320001 iterations)
found 3963 outliers among 319999 samples (1.2%)
2004 (0.6%) high severe
estimating cost of a clock call...
mean is 41.31914 ns (13 iterations)
found 1 outliers among 13 samples (7.7%)
1 (7.7%) high mild
 
benchmarking pairwise-random/extract
collecting 10 samples, 1 iterations each, in estimated 116.7755 s
mean: 11.84538 s, lb 11.71474 s, ub 12.27695 s, ci 0.950
std dev: 365.3585 ms, lb 62.28236 ms, ub 607.4764 ms, ci 0.950
found 1 outliers among 10 samples (10.0%)
1 (10.0%) high severe
variance introduced by outliers: 9.000%
variance is slightly inflated by outliers
 
benchmarking pairwise-random/slice
mean: 28.16506 ms, lb 28.01538 ms, ub 28.40334 ms, ci 0.950
std dev: 314.9693 us, lb 173.8556 us, ub 482.0836 us, ci 0.950
found 2 outliers among 10 samples (20.0%)
1 (10.0%) high mild
1 (10.0%) high severe
variance introduced by outliers: 9.000%
variance is slightly inflated by outliers

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.