Commits

Aleksey Khudyakov committed d3c5637

Add benchmarks to cabal file

Comments (0)

Files changed (3)

bench/bin.hs

-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE TypeFamilies #-}
-import Control.Monad
-import Control.Monad.ST
-import qualified Data.Vector.Unboxed as U
-import System.Random.MWC
-import Criterion.Main
-
-import Data.Histogram.Fill
-import Data.Histogram
-
-
-main :: IO ()
-main =
-  defaultMain
-  [ bgroup "bin"
-    [ bench "BinI"       $ nf (toIndex (binI0 10))      4
-    , bench "BinInt"     $ nf (toIndex (BinInt 4 4 4))  12
-    , bench "BinD"       $ nf (toIndex (binD 0 10 1))   0.33
-    , bench "BinF::F"    $ nf (toIndex (binF 0 10 1))  (0.33 :: Float)
-    , bench "BinF::D"    $ nf (toIndex (binF 0 10 1))  (0.33 :: Double)
-    , bench "BinI><BinI" $ nf (toIndex (binI0 10    >< binI0 10   )) (3,5)
-    , bench "BinD><BinD" $ nf (toIndex (binD 0 10 1 >< binD 0 10 1)) (0.3,0.5)
-    ]
-  , bgroup "hist"
-    [ bench "BinI-2"    $ nf (fill (forceInt    -<< mkSimple   (binI0 100))) (mkRange  100)
-    , bench "BinI-3"    $ nf (fill (forceInt    -<< mkSimple   (binI0 100))) (mkRange  1000)
-    , bench "BinI-4"    $ nf (fill (forceInt    -<< mkSimple   (binI0 100))) (mkRange  10000)
-    , bench "BinI-w2"   $ nf (fill (forceDouble -<< mkWeighted (binI0 100))) (mkRangeW 100)
-    , bench "BinI-w3"   $ nf (fill (forceDouble -<< mkWeighted (binI0 100))) (mkRangeW 1000)
-    , bench "BinI-w4"   $ nf (fill (forceDouble -<< mkWeighted (binI0 100))) (mkRangeW 10000)
-    ]
-  ]
-
--- Fill histogram from vector
-fill :: (U.Unbox a, Bin bin, Num val)
-      => HBuilder a (Histogram bin val) -> U.Vector a -> Histogram bin val
-fill hb vec = runST $ do
-  h <- toHBuilderST hb
-  U.mapM_ (feedOne h) vec
-  freezeHBuilderM h
-{-# INLINE fill #-}
-
-mkRange n = runST $ do
-  gen <- create
-  U.replicateM n (uniform gen)
-
-mkRangeW n = runST $ do
-  gen <- create
-  U.replicateM n $ liftM2 (,) (uniformR (-10,110) gen) (uniformR (0,10) gen)

benchmarks/benchmark.hs

+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE TypeFamilies #-}
+import Control.Monad
+import Control.Monad.ST
+import qualified Data.Vector.Unboxed as U
+import System.Random.MWC
+import Criterion.Main
+
+import Data.Histogram.Fill
+import Data.Histogram
+
+
+main :: IO ()
+main =
+  defaultMain
+  [ bgroup "bin"
+    [ bench "BinI"       $ nf (toIndex (binI0 10))      4
+    , bench "BinInt"     $ nf (toIndex (BinInt 4 4 4))  12
+    , bench "BinD"       $ nf (toIndex (binD 0 10 1))   0.33
+    , bench "BinF::F"    $ nf (toIndex (binF 0 10 1))  (0.33 :: Float)
+    , bench "BinF::D"    $ nf (toIndex (binF 0 10 1))  (0.33 :: Double)
+    , bench "BinI><BinI" $ nf (toIndex (binI0 10    >< binI0 10   )) (3,5)
+    , bench "BinD><BinD" $ nf (toIndex (binD 0 10 1 >< binD 0 10 1)) (0.3,0.5)
+    ]
+  , bgroup "hist"
+    [ bench "BinI-2"    $ nf (fill (forceInt    -<< mkSimple   (binI0 100))) (mkRange  100)
+    , bench "BinI-3"    $ nf (fill (forceInt    -<< mkSimple   (binI0 100))) (mkRange  1000)
+    , bench "BinI-4"    $ nf (fill (forceInt    -<< mkSimple   (binI0 100))) (mkRange  10000)
+    , bench "BinI-w2"   $ nf (fill (forceDouble -<< mkWeighted (binI0 100))) (mkRangeW 100)
+    , bench "BinI-w3"   $ nf (fill (forceDouble -<< mkWeighted (binI0 100))) (mkRangeW 1000)
+    , bench "BinI-w4"   $ nf (fill (forceDouble -<< mkWeighted (binI0 100))) (mkRangeW 10000)
+    ]
+  ]
+
+-- Fill histogram from vector
+fill :: (U.Unbox a, Bin bin, Num val)
+      => HBuilder a (Histogram bin val) -> U.Vector a -> Histogram bin val
+fill hb vec = runST $ do
+  h <- toHBuilderST hb
+  U.mapM_ (feedOne h) vec
+  freezeHBuilderM h
+{-# INLINE fill #-}
+
+mkRange n = runST $ do
+  gen <- create
+  U.replicateM n (uniform gen)
+
+mkRangeW n = runST $ do
+  gen <- create
+  U.replicateM n $ liftM2 (,) (uniformR (-10,110) gen) (uniformR (0,10) gen)

histogram-fill.cabal

 License-File:   LICENSE
 Author:         Alexey Khudyakov
 Maintainer:     Alexey Khudyakov <alexey.skladnoy@gmail.com>
-Homepage:       http://bitbucket.org/Shimuuar/histogram-fill/
+Homepage:       https://bitbucket.org/Shimuuar/histogram-fill/
+Bug-tracker:	https://github.com/Shimuuar/histogram-fill/issues
 Category:       Data
 Build-Type:     Simple
 extra-source-files:
   location: http://github.com/Shimuuar/histogram-fill
 
 Library
-  Build-Depends:        base >=3 && <5,
-                        deepseq,
-                        primitive,
-                        vector >= 0.10.0.1
-  Exposed-modules:      Data.Histogram
-                        Data.Histogram.Generic
-                        Data.Histogram.Fill
-                        Data.Histogram.Bin
-                        Data.Histogram.Bin.Classes
-                        Data.Histogram.Bin.BinI
-                        Data.Histogram.Bin.BinInt
-                        Data.Histogram.Bin.BinEnum
-                        Data.Histogram.Bin.BinF
-                        Data.Histogram.Bin.LogBinD
-                        Data.Histogram.Bin.MaybeBin
-                        Data.Histogram.Bin.Bin2D
-                        Data.Histogram.Bin.Extra
-                        Data.Histogram.Bin.Read
-                        Data.Histogram.ST
   Ghc-options:          -O2 -Wall
   Ghc-prof-options:     -auto-all
+  Build-Depends:
+    base >=3 && <5,
+    deepseq,
+    primitive,
+    vector >= 0.10.0.1
+  Exposed-modules:
+    Data.Histogram
+    Data.Histogram.Generic
+    Data.Histogram.Fill
+    Data.Histogram.Bin
+    Data.Histogram.Bin.Classes
+    Data.Histogram.Bin.BinI
+    Data.Histogram.Bin.BinInt
+    Data.Histogram.Bin.BinEnum
+    Data.Histogram.Bin.BinF
+    Data.Histogram.Bin.LogBinD
+    Data.Histogram.Bin.MaybeBin
+    Data.Histogram.Bin.Bin2D
+    Data.Histogram.Bin.Extra
+    Data.Histogram.Bin.Read
+    Data.Histogram.ST
 
 test-suite tests
   type:           exitcode-stdio-1.0
   main-is:        QC.hs
   other-modules:  QC.Instances
   ghc-options:    -Wall
-  build-depends:  base >=3 && < 5,
-                  histogram-fill,
-                  vector,
-                  QuickCheck >= 2,
-                  test-framework,
-                  test-framework-quickcheck2
+  build-depends:
+    base >=3 && < 5,
+    histogram-fill,
+    vector,
+    QuickCheck >= 2,
+    test-framework,
+    test-framework-quickcheck2
+
+Benchmark benchmarks
+  Type:           exitcode-stdio-1.0
+  Main-is:        benchmark.hs
+  hs-source-dirs: benchmarks
+  build-depends:
+    base >=3 && <5,
+    histogram-fill,
+    mwc-random,
+    vector,
+    criterion