fast-builder 0.0.0.0 → 0.0.0.1
raw patch · 3 files changed
+68/−3 lines, 3 filesdep +containersdep ~basedep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependencies added: containers
Dependency ranges changed: base, bytestring
API changes (from Hackage documentation)
Files
- Data/ByteString/FastBuilder/Internal.hs +2/−1
- benchmarks/map.hs +55/−0
- fast-builder.cabal +11/−2
Data/ByteString/FastBuilder/Internal.hs view
@@ -463,7 +463,8 @@ -- | Turn a value of type @a@ into a 'Builder', using the given 'PI.BoundedPrim'. primBounded :: PI.BoundedPrim a -> a -> Builder-primBounded prim !x = mappend (ensureBytes $ PI.sizeBound prim) $ mkBuilder $ do+primBounded prim x = rebuild $ seq x $ mkBuilder $ do+ useBuilder $ ensureBytes $ PI.sizeBound prim cur <- getCur cur' <- io $ PI.runB prim x cur setCur cur'
+ benchmarks/map.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE DeriveFunctor #-}+import Control.Concurrent+import Criterion.Main+import qualified Data.IntMap as IM+import Data.Monoid+import qualified System.IO as IO++import qualified Data.ByteString.Builder as Bstr+import qualified Data.ByteString.FastBuilder as Fast++main :: IO ()+main = runInUnboundThread $ do+ h <- IO.openFile "/dev/null" IO.WriteMode+ let+ size sz m = bgroup sz+ [ bench "lazy/fast" $ nf (Fast.toLazyByteString . fastMap) m+ , bench "lazy/bstr" $ nf (Bstr.toLazyByteString . bstrMap) m+ ]+ map10 `seq` map100 `seq` map1000 `seq` map10000 `seq` defaultMain+ [ size "10" map10+ , size "100" map100+ , size "1000" map1000+ , size "10000" map10000+ ]++type Map = IM.IntMap Int++fastMap :: Map -> Fast.Builder+fastMap = Fast.rebuild . IM.foldMapWithKey f+ where+ f key val =+ Fast.int32LE (fromIntegral key) <> Fast.int32LE (fromIntegral val)++bstrMap :: Map -> Bstr.Builder+bstrMap = IM.foldMapWithKey f+ where+ f key val =+ Bstr.int32LE (fromIntegral key) <> Bstr.int32LE (fromIntegral val)++map10 :: Map+map10 = makeItems 10++map100 :: Map+map100 = makeItems 100++map1000 :: Map+map1000 = makeItems 1000++map10000 :: Map+map10000 = makeItems 10000++makeItems :: Int -> Map+makeItems n = IM.fromList $ do+ i <- [0..n-1]+ return (i * 3, i)
fast-builder.cabal view
@@ -1,8 +1,10 @@ name: fast-builder-version: 0.0.0.0+version: 0.0.0.1 synopsis: Fast ByteString Builder description: An efficient implementation of ByteString builder. It should be faster than the standard implementation in most cases.+ .+ In many benchmarks, the performance improvement is 2x-10x. homepage: http://github.com/takano-akio/fast-builder license: PublicDomain license-file: LICENSE@@ -20,7 +22,7 @@ other-modules: Data.ByteString.FastBuilder.Internal.Prim -- other-extensions: - build-depends: base ==4.8.0.0, bytestring >= 0.10.6.0, ghc-prim+ build-depends: base >= 4.8 && < 4.9, bytestring >= 0.10.6.0, ghc-prim -- hs-source-dirs: default-language: Haskell2010 ghc-options: -Wall -g@@ -39,6 +41,13 @@ main-is: vector.hs hs-source-dirs: benchmarks build-depends: base, fast-builder, criterion, bytestring, vector, deepseq+ ghc-options: -Wall -threaded -g -rtsopts -eventlog++benchmark map+ type: exitcode-stdio-1.0+ main-is: map.hs+ hs-source-dirs: benchmarks+ build-depends: base, fast-builder, criterion, bytestring, containers, deepseq ghc-options: -Wall -threaded -g -rtsopts -eventlog test-suite prop