hw-prim 0.6.2.8 → 0.6.2.9
raw patch · 4 files changed
+37/−7 lines, 4 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ HaskellWorks.Data.ByteString: rechunk :: Int -> [ByteString] -> [ByteString]
Files
- bench/Main.hs +9/−6
- hw-prim.cabal +1/−1
- src/HaskellWorks/Data/ByteString.hs +17/−0
- test/HaskellWorks/Data/ByteStringSpec.hs +10/−0
bench/Main.hs view
@@ -39,19 +39,22 @@ let !_ = DVS.foldl' (+) 0 v return () -sumFileLazyByteStringViaVector64 :: FilePath -> IO ()-sumFileLazyByteStringViaVector64 filePath = do+sumFileLazyByteStringViaVector64 :: Int -> FilePath -> IO ()+sumFileLazyByteStringViaVector64 multiple filePath = do !bs <- LBS.readFile filePath- let wss = asVector64s 64 bs+ let wss = asVector64s multiple bs let !_ = sum (DVS.foldl' (+) 0 <$> wss) return () benchRankJson40Conduits :: [Benchmark] benchRankJson40Conduits = [ env (return ()) $ \_ -> bgroup "medium.csv"- [ bench "Foldl' over ByteString" (whnfIO (sumFileByteString "corpus/medium.csv"))- , bench "Foldl' over Vector Word64" (whnfIO (sumFileVector64 "corpus/medium.csv"))- , bench "Foldl' over Lazy ByteString via Vector Word64" (whnfIO (sumFileLazyByteStringViaVector64 "corpus/medium.csv"))+ -- [ bench "Foldl' over ByteString" (whnfIO (sumFileByteString "corpus/medium.csv"))+ -- , bench "Foldl' over Vector Word64" (whnfIO (sumFileVector64 "corpus/medium.csv"))+ [ bench "Foldl' over Lazy ByteString via Vector Word64" (whnfIO (sumFileLazyByteStringViaVector64 512 "corpus/medium.csv"))+ , bench "Foldl' over Lazy ByteString via Vector Word64" (whnfIO (sumFileLazyByteStringViaVector64 256 "corpus/medium.csv"))+ , bench "Foldl' over Lazy ByteString via Vector Word64" (whnfIO (sumFileLazyByteStringViaVector64 128 "corpus/medium.csv"))+ , bench "Foldl' over Lazy ByteString via Vector Word64" (whnfIO (sumFileLazyByteStringViaVector64 64 "corpus/medium.csv")) ] ]
hw-prim.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: hw-prim-version: 0.6.2.8+version: 0.6.2.9 synopsis: Primitive functions and data types description: Primitive functions and data types. category: Data
src/HaskellWorks/Data/ByteString.hs view
@@ -5,6 +5,7 @@ , ToByteString(..) , resegment , resegmentPadded+ , rechunk ) where import Data.Semigroup ((<>))@@ -48,6 +49,22 @@ else case BS.splitAt n bs of (as, zs) -> as : chunkedBy n zs {-# INLINE chunkedBy #-}++rechunk :: Int -> [BS.ByteString] -> [BS.ByteString]+rechunk size = go+ where go (bs:bss) = let bsLen = BS.length bs in+ if bsLen < size+ then case size - bsLen of+ bsNeed -> case bss of+ (cs:css) -> case BS.length cs of+ csLen | csLen > bsNeed -> (bs <> BS.take bsNeed cs ):go (BS.drop bsNeed cs:css)+ csLen | csLen == bsNeed -> (bs <> cs ):go css+ _ | otherwise -> go ((bs <> cs) :css)+ [] -> [bs]+ else if size == bsLen+ then bs:go bss+ else BS.take size bs:go (BS.drop size bs:bss)+ go [] = [] resegment :: Int -> [BS.ByteString] -> [BS.ByteString] resegment multiple = go
test/HaskellWorks/Data/ByteStringSpec.hs view
@@ -35,3 +35,13 @@ chunkSize <- forAll $ G.int (R.linear 1 4) forM_ (reverse (BS.resegmentPadded chunkSize bss)) $ \bs -> do (BS.length bs) `mod` chunkSize === 0+ it "rechunk does not modify data" $ requireProperty $ do+ bss <- forAll $ (BS.pack <$>) <$> G.list (R.linear 0 8) (G.list (R.linear 0 24) (G.word8 R.constantBounded))+ chunkSize <- forAll $ G.int (R.linear 1 4)+ mconcat (BS.rechunk chunkSize bss) === mconcat bss+ it "rechunk creates correctly sized segments" $ requireProperty $ do+ bss <- forAll $ (BS.pack <$>) <$> G.list (R.linear 0 8) (G.list (R.linear 0 24) (G.word8 R.constantBounded))+ chunkSize <- forAll $ G.int (R.linear 1 4)+ forM_ (drop 1 (reverse (BS.rechunk chunkSize bss))) $ \bs -> do+ (BS.length bs) `mod` chunkSize === 0+