We're trying to benchmark binary encoding with Criterion. Since the data types are strict, we are perfectly able to benchmark the process of packing a Request.

However, one step further by trying to benchmark the process of encode (Request to ByteString) using runPut we end up getting μs-results. This is probably due to lazy bytestring evaluation.

encode = runPut . buildRqMessage main = do randBytes <- getEntropy 1000000 let !topicA = stringToTopic "performance-0" let !topicB = stringToTopic "performance-1" let !clientId = stringToClientId "benchmark-producer" let !bytes = [randBytes | x <- [1..1]] let !head = Head 0 0 clientId let !prod = [ ToTopic topicA [ ToPart 0 bytes ] ] defaultMain [ bgroup "encode" [ bench "pack" $ whnf (packPrRqMessage head) prod , bench "pack+build" $ whnf encode (packPrRqMessage head prod) ] ]

Is there a way to benchmark the encode process appropriately?