3 ms·
My experience with benchmarking is that the benchmark program must actually do something with the result (like, printing it). Not only because you cannot trust
by Athas 10y ago
My experience with benchmarking is that the benchmark program must actually do something with the result (like, printing it). Not only because you cannot trust a benchmark to do self-validation, but also because you otherwise end up fighting the optimiser.
You don't have to print the result within the body of code that you are timing (which would skew the result), but you must have some confidence that the benchmarking setup is sufficiently close to real-world usage conditions. This usually involves the computation now knowing how its result is going to be used.
(In a similar vein, I am also very skeptical about benchmark programs that hard-code their input, rather than read it at runtime.)
- Ono-Sendai 10y agoYou can just print the result after you have finished measuring the loop.
- mason55 10y agoUnless you're using a language with lazy evaluation
- tomsmeding 10y agoIn which case there is probably some sequencing function that you can use (seq or deepseq in haskell, for example)
- Athas 10y agoYes, exactly. That is what I usually do.