@@ -31,7 +31,7 @@ import Streamly.Internal.Data.Unbox
3131import Control.DeepSeq (force)
3232import Test.QuickCheck (oneof, generate)
3333import Streamly.Internal.Data.Unbox (newBytes, MutableByteArray)
34−import Streamly.Internal.Data.Serialize
34+import Streamly.Internal.Data.Serialize hiding (encode)
3535#endif
3636
3737#ifdef USE_TH
@@ -353,6 +353,17 @@ pokeTimes val times = do
353353 arr <- newBytes n
354354 loopWith times poke arr val
355355
356+{-# INLINE encode #-}
357+encode :: SERIALIZE_CLASS a => a -> IO ()
358+encode val = do
359+ let n = getSize val
360+ arr <- newBytes n
361+ SERIALIZE_OP 0 arr val >> return ()
362+
363+{-# INLINE encodeTimes #-}
364+encodeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
365+encodeTimes val times = loop times encode val
366+
356367{-# INLINE peek #-}
357368peek :: forall a. (NFData a, SERIALIZE_CLASS a) =>
358369 (a, Int) -> MutableByteArray -> IO ()
@@ -478,11 +489,13 @@ allBenchmarks tInt lInt times =
478489 ]
479490 , benchConst "poke" (const pokeTimes) times
480491 , benchConst "pokeWithSize" (const pokeTimesWithSize) times
492+ , benchConst "encode" (const encodeTimes) times
481493 , benchConst "peek" peekTimes times
482494 , benchConst "roundtrip" (const roundtrip) times
483495#ifndef USE_UNBOX
484496 , benchVar "poke" (const pokeTimes) tInt lInt 1
485497 , benchVar "pokeWithSize" (const pokeTimesWithSize) tInt lInt 1
498+ , benchVar "encode" (const encodeTimes) tInt lInt 1
486499 , benchVar "peek" peekTimes tInt lInt 1
487500 , benchVar "roundtrip" (const roundtrip) tInt lInt 1
488501#endif