module Main where
import Data
.Array
.Repa
hiding (map) import Criterion.Main
type DIM1
_U
_D
= Array U DIM1
Double type DIM1
_D
_D
= Array D DIM1
Double type DIM2
_D
_D
= Array D DIM2
Double
calc :: DIM1_U_D -> DIM1_U_D -> DIM1_D_D
calc k b = let sizeB = size (extent b)
sizeK = size (extent k)
(\i -> kp (Z:.i) * bp (Z:.ic+i))
[0..sizeK-1]
in traverse2 k b (\_ _ -> Z:.sizeB-sizeK+1) p
calc0
, calc1
:: DIM1
_U
_D
-> DIM1
_U
_D
-> IO DIM1
_U
_D
calc0 k b = computeP $ calc k b
calc1 k b = let Z :. ks = extent k
Z :. bs = extent b
sh = Z :. bs - ks + 1 :. ks
k', b' :: DIM2_D_D
k' = traverse k (const sh) (\f (Z :. _ :. j) -> f (Z :. j))
b' = traverse b
(const sh
) (\f
(Z :
. i :
. j
) -> f
(Z :
. (i
+j
))) in sumP $ k' *^ b'
-- kernel = [6, 3, 5]
-- base = [3, 5, 2, 9, 4]
kernel = [1..100]
base = [1..10000]
main = do
-- print =<< calc0 k b
-- print =<< calc1 k b
defaultMain [bench "calc0" $ calc0 k b,
bench "calc1" $ calc1 k b]
{- COMMAND
ghc -O2 -rtsopts -threaded --make 265.hs
sleep 100
./265 +RTS -N
-}
{- RESULT
benchmarking calc0
mean: 39.45803 ms, lb 38.17716 ms, ub 40.52058 ms, ci 0.950
std dev: 5.970122 ms, lb 4.884646 ms, ub 7.284042 ms, ci 0.950
found 20 outliers among 100 samples (20.0%)
10 (10.0%) low severe
3 (3.0%) low mild
7 (7.0%) high mild
variance introduced by outliers: 90.435%
variance is severely inflated by outliers
benchmarking calc1
collecting 100 samples, 1 iterations each, in estimated 16.56821 s
mean: 256.1315 ns, lb 158.3799 ns, ub 349.1148 ns, ci 0.950
std dev: 490.1614 ns, lb 471.0462 ns, ub 506.4769 ns, ci 0.950
variance introduced by outliers: 98.996%
variance is severely inflated by outliers
-}
bW9kdWxlIE1haW4gd2hlcmUKIAppbXBvcnQgRGF0YS5BcnJheS5SZXBhIGhpZGluZyAobWFwKQppbXBvcnQgQ3JpdGVyaW9uLk1haW4KCnR5cGUgRElNMV9VX0QgPSBBcnJheSBVIERJTTEgRG91YmxlCnR5cGUgRElNMV9EX0QgPSBBcnJheSBEIERJTTEgRG91YmxlCnR5cGUgRElNMl9EX0QgPSBBcnJheSBEIERJTTIgRG91YmxlCgpjYWxjIDo6IERJTTFfVV9EIC0+IERJTTFfVV9EIC0+IERJTTFfRF9ECmNhbGMgayBiID0gbGV0IHNpemVCID0gc2l6ZSAoZXh0ZW50IGIpCiAgICAgICAgICAgICAgIHNpemVLID0gc2l6ZSAoZXh0ZW50IGspCiAgICAgICAgICAgICAgIHAga3AgYnAgKFo6LmljKSA9IHN1bSAkIG1hcAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoXGkgLT4ga3AgKFo6LmkpICogYnAgKFo6LmljK2kpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBbMC4uc2l6ZUstMV0KICAgICAgICAgICBpbiB0cmF2ZXJzZTIgayBiIChcXyBfIC0+IFo6LnNpemVCLXNpemVLKzEpIHAKCmNhbGMwLCBjYWxjMSA6OiBESU0xX1VfRCAtPiBESU0xX1VfRCAtPiBJTyBESU0xX1VfRApjYWxjMCBrIGIgPSBjb21wdXRlUCAkIGNhbGMgayBiIAoKY2FsYzEgayBiID0gbGV0IFogOi4ga3MgPSBleHRlbnQgawogICAgICAgICAgICAgICAgWiA6LiBicyA9IGV4dGVudCBiCiAgICAgICAgICAgICAgICBzaCA9IFogOi4gYnMgLSBrcyArIDEgOi4ga3MKICAgICAgICAgICAgICAgIGsnLCBiJyA6OiBESU0yX0RfRAogICAgICAgICAgICAgICAgaycgPSB0cmF2ZXJzZSBrIChjb25zdCBzaCkgKFxmIChaIDouIF8gOi4gaikgLT4gZiAoWiA6LiBqKSkKICAgICAgICAgICAgICAgIGInID0gdHJhdmVyc2UgYiAoY29uc3Qgc2gpIChcZiAoWiA6LiBpIDou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