packages feed

mono-traversable 0.4.0.3 → 0.4.0.4

raw patch · 3 files changed

+49/−6 lines, 3 filesdep +criteriondep +mwc-randomdep ~basedep ~vector

Dependencies added: criterion, mwc-random

Dependency ranges changed: base, vector

Files

+ bench/sorting.hs view
@@ -0,0 +1,31 @@+import Criterion.Main+import Data.Sequences+import Data.MonoTraversable+import qualified Data.List+import qualified System.Random.MWC as MWC+import qualified Data.Vector as V+import qualified Data.Vector.Unboxed as U++asVector :: V.Vector a -> V.Vector a+asVector = id++asUVector :: U.Vector a -> U.Vector a+asUVector = id++main :: IO ()+main = do+    mapM mkGroup [10, 100, 1000, 10000] >>= defaultMain++mkGroup :: Int -> IO Benchmark+mkGroup size = do+    inputV <- MWC.withSystemRandom . MWC.asGenST $ flip MWC.uniformVector size+    let inputL = otoList (inputV :: V.Vector Int)+        inputVU = fromList inputL :: U.Vector Int+    return $ bgroup (show size)+        [ bench "Data.List.sort" $ nf Data.List.sort inputL+        , bench "list sort" $ nf sort inputL+        , bench "list sort, via vector" $ nf (otoList . sort . asVector . fromList) inputL+        , bench "list sort, via uvector" $ nf (otoList . sort . asUVector . fromList) inputL+        , bench "vector sort" $ nf sort inputV+        , bench "uvector sort" $ nf sort inputVU+        ]
mono-traversable.cabal view
@@ -1,5 +1,5 @@ name:                mono-traversable-version:             0.4.0.3+version:             0.4.0.4 synopsis:            Type classes for mapping, folding, and traversing monomorphic containers description:         Monomorphic variants of the Functor, Foldable, and Traversable typeclasses. Contains even more experimental code for abstracting containers and sequences. homepage:            https://github.com/snoyberg/mono-traversable@@ -56,6 +56,18 @@                      , containers                      , unordered-containers                      , foldl++benchmark sorting+    type: exitcode-stdio-1.0+    hs-source-dirs: bench+    build-depends:  base+                  , criterion+                  , mono-traversable+                  , vector+                  , mwc-random+    main-is:        sorting.hs+    ghc-options:    -Wall -O2+    default-language:    Haskell2010                       source-repository head   type: git
src/Data/Sequences.hs view
@@ -199,7 +199,7 @@ {-# INLINE defaultReverse #-}  defaultSortBy :: IsSequence seq => (Element seq -> Element seq -> Ordering) -> seq -> seq-defaultSortBy f = fromList . List.sortBy f . otoList+defaultSortBy f = fromList . sortBy f . otoList {-# INLINE defaultSortBy #-}  vectorSortBy :: VG.Vector v e => (e -> e -> Ordering) -> v e -> v e@@ -237,7 +237,7 @@     intersperse = List.intersperse     reverse = List.reverse     find = List.find-    sortBy = List.sortBy+    sortBy f = V.toList . sortBy f . V.fromList     cons = (:)     snoc = defaultSnoc     {-# INLINE intersperse #-}@@ -310,7 +310,7 @@     find         = find     cons         = NE.cons     snoc xs x    = NE.fromList $ flip snoc x $ NE.toList xs-    sortBy f     = NE.fromList . List.sortBy f . NE.toList+    sortBy f     = NE.fromList . sortBy f . NE.toList     {-# INLINE intersperse #-}     {-# INLINE reverse #-}     {-# INLINE find #-}@@ -1012,11 +1012,11 @@  class (EqSequence seq, MonoFoldableOrd seq) => OrdSequence seq where     sort :: seq -> seq-    sort = fromList . List.sort . otoList+    sort = fromList . sort . otoList     {-# INLINE sort #-}  instance Ord a => OrdSequence [a] where-    sort = List.sort+    sort = V.toList . sort . V.fromList     {-# INLINE sort #-}  instance OrdSequence S.ByteString where