on master help sign in
Enable the comparison after deserialization
43e25a1Harendra Kumar
benchmark/Streamly/Benchmark/Data/Serialize.hs+10−14
@@ -18,7 +18,6 @@ module Main (main) where
18-------------------------------------------------------------------------------
18-------------------------------------------------------------------------------
19
19
20import Control.DeepSeq (NFData(..))
20import Control.DeepSeq (NFData(..))
21−import Control.Exception (assert)
22import GHC.Generics (Generic)
21import GHC.Generics (Generic)
23import System.Random (randomRIO)
22import System.Random (randomRIO)
24#ifndef USE_UNBOX
23#ifndef USE_UNBOX
@@ -313,17 +312,16 @@ peek val arr = do
313 (_, val1 :: a)
312 (_, val1 :: a)
314#endif
313#endif
315 <- DESERIALIZE_OP 0 arr
314 <- DESERIALIZE_OP 0 arr
316− assert (val == val1) (pure ())
317− -- Ensure that we are actually constructing the type and using it.
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− -- Otherwise we may just read the values and discard them.
318+ -- just read the values and discard them. The comparison adds to the
319− -- The comparison adds to the cost though.
319+ -- cost though. We could use deepseq but then we need to write
320− --
320+ -- instances of NFData and ensure that they are correct and perform
321− {-
321+ -- well. Equality check also ensures correctness.
322 if (val1 /= val)
322 if (val1 /= val)
323 then error "peek: no match"
323 then error "peek: no match"
324 else return ()
324 else return ()
325− -}
326− return ()
327
325
328{-# INLINE peekTimes #-}
326{-# INLINE peekTimes #-}
329peekTimes :: (Eq a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
327peekTimes :: (Eq a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
@@ -344,14 +342,10 @@ trip val = do
344 (_, val1)
342 (_, val1)
345#endif
343#endif
346 <- DESERIALIZE_OP 0 arr
344 <- DESERIALIZE_OP 0 arr
347− assert (val == val1) (pure ())
345+ -- Do not remove this, see the comments in peek.
348− -- So that the compiler does not optimize it out
349− {-
350 if (val1 /= val)
346 if (val1 /= val)
351 then error "roundtrip: no match"
347 then error "roundtrip: no match"
352 else return ()
348 else return ()
353− -}
354− return ()
355
349
356{-# INLINE roundtrip #-}
350{-# INLINE roundtrip #-}
357roundtrip :: (Eq a, SERIALIZE_CLASS a) => a -> Int -> IO ()
351roundtrip :: (Eq a, SERIALIZE_CLASS a) => a -> Int -> IO ()
@@ -473,6 +467,8 @@ main = do
473 -- peekTimes (Sum2525) value
467 -- peekTimes (Sum2525) value
474 -- 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
468 -- 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
475 -- peekTimes tInt 1
469 -- peekTimes tInt 1
470+ let !n = getSize lInt
471+ peekTimes n lInt 1
476
472
477 -- roundtrip ((CDT1C2 (5 :: Int)) :: CustomDT1) value
473 -- roundtrip ((CDT1C2 (5 :: Int)) :: CustomDT1) value
478 return ()
474 return ()