Skip to content

Instantly share code, notes, and snippets.

@aeyakovenko
Last active August 29, 2015 14:17
Show Gist options
  • Save aeyakovenko/0af788390ee9d980c1d6 to your computer and use it in GitHub Desktop.
Save aeyakovenko/0af788390ee9d980c1d6 to your computer and use it in GitHub Desktop.
module Test where
--impl modules
import Data.Array.Repa.Algorithms.Randomish
import Data.Array.Repa
import Criterion.Main
import System.Environment(getArgs)
main :: IO ()
main = do
let
f (Z :. r :. c) = (fromIntegral r) * (fromIntegral c)
sh :: DIM2
sh = Z :. 10000 :. 10000
f1 :: IO Double
f1 = do
a <- computeUnboxedP (fromFunction sh f)
a `deepSeqArray` sumAllP a
f2 :: IO Double
f2 = do
let a = computeUnboxedS $ fromFunction sh f
a `deepSeqArray` sumAllP $ a
f3 :: DIM2 -> Double
f3 sh' = sumAllS $ computeUnboxedS $ fromFunction sh' f
defaultMain [
bench "f1" $ nfIO $ f1
, bench "f2" $ nfIO $ f2
, bench "f3" $ whnf f3 sh
]
{--
$ time ./dist/build/test/test +RTS -N4
benchmarking f1
time 1.376 s (1.177 s .. 1.527 s)
0.998 R² (0.992 R² .. 1.000 R²)
mean 1.388 s (1.363 s .. 1.426 s)
std dev 33.08 ms (271.9 as .. 35.95 ms)
variance introduced by outliers: 19% (moderately inflated)
benchmarking f2
time 1.698 s (1.586 s .. 1.883 s)
0.999 R² (0.996 R² .. 1.000 R²)
mean 1.634 s (1.607 s .. 1.676 s)
std dev 37.09 ms (0.0 s .. 39.80 ms)
variance introduced by outliers: 19% (moderately inflated)
benchmarking f3
time 7.644 s (7.533 s .. 7.824 s)
1.000 R² (1.000 R² .. 1.000 R²)
mean 7.763 s (7.708 s .. 7.808 s)
std dev 70.25 ms (0.0 s .. 77.52 ms)
variance introduced by outliers: 19% (moderately inflated)
$ time ./dist/build/test/test +RTS -N1
benchmarking f1
time 3.307 s (1.858 s .. 4.448 s)
0.979 R² (0.922 R² .. 1.000 R²)
mean 3.331 s (3.177 s .. 3.616 s)
std dev 247.2 ms (543.9 as .. 253.7 ms)
variance introduced by outliers: 21% (moderately inflated)
benchmarking f2
time 3.168 s (3.044 s .. 3.237 s)
1.000 R² (1.000 R² .. 1.000 R²)
mean 3.172 s (3.155 s .. 3.184 s)
std dev 18.60 ms (0.0 s .. 21.31 ms)
variance introduced by outliers: 19% (moderately inflated)
benchmarking f3
time 5.542 s (2.284 s .. 7.814 s)
0.951 R² (0.902 R² .. 1.000 R²)
mean 6.302 s (5.527 s .. 6.717 s)
std dev 676.1 ms (1.088 fs .. 718.1 ms)
variance introduced by outliers: 23% (moderately inflated)
--}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment