Skip to content

Commit b475a44

Browse files
committed
Update unconsN benchmark with split/unpack variant
1 parent a77eedf commit b475a44

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

bench/BenchShort.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE ViewPatterns #-}
23
{-# LANGUAGE PackageImports #-}
34
{-# LANGUAGE ScopedTypeVariables #-}
45
{-# LANGUAGE MagicHash #-}
@@ -251,6 +252,7 @@ benchShort = bgroup "ShortByteString"
251252
[ bench "unpack and look at first 5 elements" $ nf (unpack5) absurdlong
252253
, bench "uncons consecutively 5 times" $ nf (uncons5) absurdlong
253254
, bench "unconsN 5" $ nf (unconsN) absurdlong
255+
, bench "unconsNViaSplit 5" $ nf (unconsNViaSplit) absurdlong
254256
]
255257
]
256258

@@ -275,3 +277,8 @@ unconsN sbs = case S.unconsN 5 sbs of
275277
Just ([a, b, c, d, e], xs) -> True
276278
Just _ -> error "oops"
277279
_ -> False
280+
281+
unconsNViaSplit :: ShortByteString -> Bool
282+
unconsNViaSplit sbs = case S.splitAt 5 sbs of
283+
(S.unpack -> [a, b, c, d, e], xs) -> True
284+
_ -> False

0 commit comments

Comments
 (0)