on master help sign in
Enable the comparison after deserialization
commit43e25a173f010d5606bac1a45770dd77fe9e2a83 authorHarendra Kumar <harendra@composewell.com> dateSun 20 Aug 2023, 09:57 (3 years ago) parentbf3e775
1 file changed+10−14
benchmark/Streamly/Benchmark/Data/Serialize.hs+10−14
benchmark/Streamly/Benchmark/Data/Serialize.hs+10−14
@@ -18,7 +18,6 @@ module Main (main) where
1818-------------------------------------------------------------------------------
1919
2020import Control.DeepSeq (NFData(..))
21−import Control.Exception (assert)
2221import GHC.Generics (Generic)
2322import System.Random (randomRIO)
2423#ifndef USE_UNBOX
@@ -313,17 +312,16 @@ peek val arr = do
313312 (_, val1 :: a)
314313#endif
315314 <- DESERIALIZE_OP 0 arr
316− assert (val == val1) (pure ())
317− -- Ensure that we are actually constructing the type and using it.
318− -- Otherwise we may just read the values and discard them.
319− -- The comparison adds to the cost though.
320− --
321− {-
315+ -- Ensure that we are actually constructing the type and using it. This
316+ -- is important, otherwise the structure is created and discarded, the
317+ -- cost of creation of the structure is not accounted. Otherwise we may
318+ -- just read the values and discard them. The comparison adds to the
319+ -- cost though. We could use deepseq but then we need to write
320+ -- instances of NFData and ensure that they are correct and perform
321+ -- well. Equality check also ensures correctness.
322322 if (val1 /= val)
323323 then error "peek: no match"
324324 else return ()
325− -}
326− return ()
327325
328326{-# INLINE peekTimes #-}
329327peekTimes :: (Eq a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
@@ -344,14 +342,10 @@ trip val = do
344342 (_, val1)
345343#endif
346344 <- DESERIALIZE_OP 0 arr
347− assert (val == val1) (pure ())
348− -- So that the compiler does not optimize it out
349− {-
345+ -- Do not remove this, see the comments in peek.
350346 if (val1 /= val)
351347 then error "roundtrip: no match"
352348 else return ()
353− -}
354− return ()
355349
356350{-# INLINE roundtrip #-}
357351roundtrip :: (Eq a, SERIALIZE_CLASS a) => a -> Int -> IO ()
@@ -473,6 +467,8 @@ main = do
473467 -- peekTimes (Sum2525) value
474468 -- peekTimes (Product25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25) value
475469 -- peekTimes tInt 1
470+ let !n = getSize lInt
471+ peekTimes n lInt 1
476472
477473 -- roundtrip ((CDT1C2 (5 :: Int)) :: CustomDT1) value
478474 return ()