Skip to content

Commit

Permalink
Update unconsN benchmark with split/unpack variant
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Sep 30, 2022
1 parent a77eedf commit b475a44
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bench/BenchShort.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE MagicHash #-}
Expand Down Expand Up @@ -251,6 +252,7 @@ benchShort = bgroup "ShortByteString"
[ bench "unpack and look at first 5 elements" $ nf (unpack5) absurdlong
, bench "uncons consecutively 5 times" $ nf (uncons5) absurdlong
, bench "unconsN 5" $ nf (unconsN) absurdlong
, bench "unconsNViaSplit 5" $ nf (unconsNViaSplit) absurdlong
]
]

Expand All @@ -275,3 +277,8 @@ unconsN sbs = case S.unconsN 5 sbs of
Just ([a, b, c, d, e], xs) -> True
Just _ -> error "oops"
_ -> False

unconsNViaSplit :: ShortByteString -> Bool
unconsNViaSplit sbs = case S.splitAt 5 sbs of
(S.unpack -> [a, b, c, d, e], xs) -> True
_ -> False

0 comments on commit b475a44

Please sign in to comment.