fork download
  1. module Main where
  2.  
  3. import Data.Array.Repa hiding (map)
  4. import Criterion.Main
  5.  
  6. type DIM1_U_D = Array U DIM1 Double
  7. type DIM1_D_D = Array D DIM1 Double
  8. type DIM2_D_D = Array D DIM2 Double
  9.  
  10. calc :: DIM1_U_D -> DIM1_U_D -> DIM1_D_D
  11. calc k b = let sizeB = size (extent b)
  12. sizeK = size (extent k)
  13. p kp bp (Z:.ic) = sum $ map
  14. (\i -> kp (Z:.i) * bp (Z:.ic+i))
  15. [0..sizeK-1]
  16. in traverse2 k b (\_ _ -> Z:.sizeB-sizeK+1) p
  17.  
  18. calc0, calc1 :: DIM1_U_D -> DIM1_U_D -> IO DIM1_U_D
  19. calc0 k b = computeP $ calc k b
  20.  
  21. calc1 k b = let Z :. ks = extent k
  22. Z :. bs = extent b
  23. sh = Z :. bs - ks + 1 :. ks
  24. k', b' :: DIM2_D_D
  25. k' = traverse k (const sh) (\f (Z :. _ :. j) -> f (Z :. j))
  26. b' = traverse b (const sh) (\f (Z :. i :. j) -> f (Z :. (i+j)))
  27. in sumP $ k' *^ b'
  28.  
  29. kernel, base :: [Double]
  30. -- kernel = [6, 3, 5]
  31. -- base = [3, 5, 2, 9, 4]
  32.  
  33. kernel = [1..100]
  34. base = [1..10000]
  35.  
  36. main = do
  37. k <- return $! fromListUnboxed (Z :. length kernel) kernel
  38. b <- return $! fromListUnboxed (Z :. length base) base
  39. -- print =<< calc0 k b
  40. -- print =<< calc1 k b
  41. defaultMain [bench "calc0" $ calc0 k b,
  42. bench "calc1" $ calc1 k b]
  43.  
  44. {- COMMAND
  45. ghc -O2 -rtsopts -threaded --make 265.hs
  46. sleep 100
  47. ./265 +RTS -N
  48. -}
  49.  
  50. {- RESULT
  51. benchmarking calc0
  52. mean: 39.45803 ms, lb 38.17716 ms, ub 40.52058 ms, ci 0.950
  53. std dev: 5.970122 ms, lb 4.884646 ms, ub 7.284042 ms, ci 0.950
  54. found 20 outliers among 100 samples (20.0%)
  55.   10 (10.0%) low severe
  56.   3 (3.0%) low mild
  57.   7 (7.0%) high mild
  58. variance introduced by outliers: 90.435%
  59. variance is severely inflated by outliers
  60.  
  61. benchmarking calc1
  62. collecting 100 samples, 1 iterations each, in estimated 16.56821 s
  63. mean: 256.1315 ns, lb 158.3799 ns, ub 349.1148 ns, ci 0.950
  64. std dev: 490.1614 ns, lb 471.0462 ns, ub 506.4769 ns, ci 0.950
  65. variance introduced by outliers: 98.996%
  66. variance is severely inflated by outliers
  67. -}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:4:7:
    Could not find module `Criterion.Main':
      Use -v to see a list of the files searched for.
stdout
Standard output is empty