@@ -45,6 +45,11 @@ import Streamly.Internal.Data.Serialize.TH
45import Gauge
45import Gauge
46import Streamly.Benchmark.Common
46import Streamly.Benchmark.Common
49+import Streamly.Benchmark.Data.Serialize.RecCompatible
50+import Streamly.Benchmark.Data.Serialize.RecNonCompatible
48#ifdef USE_UNBOX
53#ifdef USE_UNBOX
49#define SERIALIZE_CLASS Unbox
54#define SERIALIZE_CLASS Unbox
50#define DERIVE_CLASS deriveUnbox
55#define DERIVE_CLASS deriveUnbox
@@ -474,6 +479,41 @@ benchVar gname f tInt lInt times =
474 , let !n = getSize lInt
479 , let !n = getSize lInt
475 in benchSink "list-int" times (f n lInt)
480 in benchSink "list-int" times (f n lInt)
484+{-# INLINE benchGeneric #-}
486+ :: (NFData b, Serialize b)
489+ -> (forall a. (NFData a, Serialize a) =>
490+ Int -> a -> Int -> IO ())
494+benchGeneric gname valId f val times =
496+ [ let !n = getSize val
497+ in benchSink valId times (f n val)
501+{-# INLINE benchLargeRec #-}
504+ -> (forall a. (NFData a, Serialize a) =>
505+ Int -> a -> Int -> IO ())
510+benchLargeRec gname f recL recR times =
512+ [ let !n = getSize recL
513+ in benchSink "RecNonCompatible" times (f n recL)
514+ , let !n = getSize recR
515+ in benchSink "RecCompatible" times (f n recR)
479-- Times is scaled by the number of constructors to normalize
519-- Times is scaled by the number of constructors to normalize
@@ -481,8 +521,9 @@ benchVar gname f tInt lInt times =
481allBenchmarks :: Int -> [Benchmark]
521allBenchmarks :: Int -> [Benchmark]
482allBenchmarks times =
522allBenchmarks times =
484−allBenchmarks :: BinTree Int -> [Int] -> Int -> [Benchmark]
525+ BinTree Int -> [Int] -> RecNonCompatible -> RecCompatible -> Int -> [Benchmark]
485−allBenchmarks tInt lInt times =
526+allBenchmarks tInt lInt recL recR times =
487 [ bgroup "sizeOf"
528 [ bgroup "sizeOf"
@@ -502,6 +543,10 @@ allBenchmarks tInt lInt times =
502 , benchVar "encode" (const encodeTimes) tInt lInt 1
543 , benchVar "encode" (const encodeTimes) tInt lInt 1
503 , benchVar "peek" peekTimes tInt lInt 1
544 , benchVar "peek" peekTimes tInt lInt 1
504 , benchVar "roundtrip" (const roundtrip) tInt lInt 1
545 , benchVar "roundtrip" (const roundtrip) tInt lInt 1
546+ , benchLargeRec "poke" (const pokeTimes) recL recR times
547+ , benchLargeRec "encode" (const encodeTimes) recL recR times
548+ , benchLargeRec "peek" peekTimes recL recR times
549+ , benchLargeRec "roundtrip" (const roundtrip) recL recR times
@@ -517,6 +562,9 @@ main = do
517 -- nodes 1 level = log_2 (100001/3) + 1 = 16
562 -- nodes 1 level = log_2 (100001/3) + 1 = 16
518 !(tInt :: BinTree Int) <- force <$> mkBinTree 16
563 !(tInt :: BinTree Int) <- force <$> mkBinTree 16
565+ let !recL = valRecNonCompatible
566+ let !recR = valRecCompatible
520 -- Approximately 100000 constructors, assuming two constructors (Cons, Int)
568 -- Approximately 100000 constructors, assuming two constructors (Cons, Int)
521 -- per element.
569 -- per element.
522 let lInt = [1..50000 :: Int]
570 let lInt = [1..50000 :: Int]
@@ -528,7 +576,11 @@ main = do
528#ifdef USE_UNBOX
576#ifdef USE_UNBOX
529 runWithCLIOpts defaultStreamSize allBenchmarks
577 runWithCLIOpts defaultStreamSize allBenchmarks
580+ `seq` runWithCLIOpts
531− len `seq` runWithCLIOpts defaultStreamSize (allBenchmarks tInt lInt)
582+ (allBenchmarks tInt lInt recL recR)
534 -- Enable FUSION_CHECK macro at the beginning of the file
586 -- Enable FUSION_CHECK macro at the beginning of the file