@@ -45,6 +45,11 @@ import Streamly.Internal.Data.Serialize.TH
4545import Gauge
4646import Streamly.Benchmark.Common
4747
48+#ifndef USE_UNBOX
49+import Streamly.Benchmark.Data.Serialize.RecCompatible
50+import Streamly.Benchmark.Data.Serialize.RecNonCompatible
51+#endif
52+
4853#ifdef USE_UNBOX
4954#define SERIALIZE_CLASS Unbox
5055#define DERIVE_CLASS deriveUnbox
@@ -474,6 +479,41 @@ benchVar gname f tInt lInt times =
474479 , let !n = getSize lInt
475480 in benchSink "list-int" times (f n lInt)
476481 ]
482+
483+{-
484+{-# INLINE benchGeneric #-}
485+benchGeneric
486+ :: (NFData b, Serialize b)
487+ => String
488+ -> String
489+ -> (forall a. (NFData a, Serialize a) =>
490+ Int -> a -> Int -> IO ())
491+ -> b
492+ -> Int
493+ -> Benchmark
494+benchGeneric gname valId f val times =
495+ bgroup gname
496+ [ let !n = getSize val
497+ in benchSink valId times (f n val)
498+ ]
499+-}
500+
501+{-# INLINE benchLargeRec #-}
502+benchLargeRec ::
503+ String
504+ -> (forall a. (NFData a, Serialize a) =>
505+ Int -> a -> Int -> IO ())
506+ -> RecNonCompatible
507+ -> RecCompatible
508+ -> Int
509+ -> Benchmark
510+benchLargeRec gname f recL recR times =
511+ bgroup gname
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)
516+ ]
477517#endif
478518
479519-- Times is scaled by the number of constructors to normalize
@@ -481,8 +521,9 @@ benchVar gname f tInt lInt times =
481521allBenchmarks :: Int -> [Benchmark]
482522allBenchmarks times =
483523#else
484−allBenchmarks :: BinTree Int -> [Int] -> Int -> [Benchmark]
485−allBenchmarks tInt lInt times =
524+allBenchmarks ::
525+ BinTree Int -> [Int] -> RecNonCompatible -> RecCompatible -> Int -> [Benchmark]
526+allBenchmarks tInt lInt recL recR times =
486527#endif
487528 [ bgroup "sizeOf"
488529 [
@@ -502,6 +543,10 @@ allBenchmarks tInt lInt times =
502543 , benchVar "encode" (const encodeTimes) tInt lInt 1
503544 , benchVar "peek" peekTimes tInt lInt 1
504545 , 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
505550#endif
506551 ]
507552
@@ -517,6 +562,9 @@ main = do
517562 -- nodes 1 level = log_2 (100001/3) + 1 = 16
518563 !(tInt :: BinTree Int) <- force <$> mkBinTree 16
519564
565+ let !recL = valRecNonCompatible
566+ let !recR = valRecCompatible
567+
520568 -- Approximately 100000 constructors, assuming two constructors (Cons, Int)
521569 -- per element.
522570 let lInt = [1..50000 :: Int]
@@ -528,7 +576,11 @@ main = do
528576#ifdef USE_UNBOX
529577 runWithCLIOpts defaultStreamSize allBenchmarks
530578#else
531− len `seq` runWithCLIOpts defaultStreamSize (allBenchmarks tInt lInt)
579+ len
580+ `seq` runWithCLIOpts
581+ defaultStreamSize
582+ (allBenchmarks tInt lInt recL recR)
583+
532584#endif
533585#else
534586 -- Enable FUSION_CHECK macro at the beginning of the file