我们正尝试使用Criterion对二进制编码进行基准测试。 由于数据类型是严格的,我们完全能够对包装请求的过程进行基准测试。
然而,通过尝试使用runPut对编码过程(Request to ByteString)进行基准测试,我们最终获得了μs结果。这可能是由于懒惰的字节串评估。
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)
]
]
有没有办法对编码过程进行适当的基准测试?