# statistics / benchmark / bench.hs

 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 68 import Control.Monad.ST (runST) import Data.Complex import qualified Data.Vector.Unboxed as U import System.Random.MWC import Criterion.Main import Statistics.Sample import Statistics.Transform -- Test sample sample :: U.Vector Double sample = runST \$ flip uniformVector 10000 =<< create -- Weighted test sample sampleW :: U.Vector (Double,Double) sampleW = U.zip sample (U.reverse sample) -- Comlex vector for FFT tests sampleC :: U.Vector (Complex Double) sampleC = U.zipWith (:+) sample (U.reverse sample) -- Simple benchmark for functions from Statistics.Sample main :: IO () main = defaultMain [ bgroup "sample" [ bench "range" \$ nf (\x -> range x) sample -- Mean , bench "mean" \$ nf (\x -> mean x) sample , bench "meanWeighted" \$ nf (\x -> meanWeighted x) sampleW , bench "harmonicMean" \$ nf (\x -> harmonicMean x) sample , bench "geometricMean" \$ nf (\x -> geometricMean x) sample -- Variance , bench "variance" \$ nf (\x -> variance x) sample , bench "varianceUnbiased" \$ nf (\x -> varianceUnbiased x) sample , bench "varianceWeighted" \$ nf (\x -> varianceWeighted x) sampleW -- Other , bench "stdDev" \$ nf (\x -> stdDev x) sample , bench "skewness" \$ nf (\x -> skewness x) sample , bench "kurtosis" \$ nf (\x -> kurtosis x) sample -- Central moments , bench "C.M. 2" \$ nf (\x -> centralMoment 2 x) sample , bench "C.M. 3" \$ nf (\x -> centralMoment 3 x) sample , bench "C.M. 4" \$ nf (\x -> centralMoment 4 x) sample , bench "C.M. 5" \$ nf (\x -> centralMoment 5 x) sample ] , bgroup "FFT" [ bgroup "fft" [ bench (show n) \$ whnf fft (U.take n sampleC) | n <- fftSizes ] , bgroup "ifft" [ bench (show n) \$ whnf ifft (U.take n sampleC) | n <- fftSizes ] , bgroup "dct" [ bench (show n) \$ whnf dct (U.take n sample) | n <- fftSizes ] , bgroup "dct_" [ bench (show n) \$ whnf dct_ (U.take n sampleC) | n <- fftSizes ] , bgroup "idct" [ bench (show n) \$ whnf idct (U.take n sample) | n <- fftSizes ] , bgroup "idct_" [ bench (show n) \$ whnf idct_ (U.take n sampleC) | n <- fftSizes ] ] ] fftSizes :: [Int] fftSizes = [32,128,512,2048]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.