how to benchmark pure functions?

ab not_a_real_address at nowhere.ab
Thu Oct 27 17:17:01 UTC 2022


Hi,

when trying to compare different implementations of the optimized 
builds of a pure function using benchmark from 
std.datetime.stopwatch, I get times equal to zero, I suppose 
because the functions are not executed as they do not have side 
effects.

The same happens with the example from the documentation:
https://dlang.org/library/std/datetime/stopwatch/benchmark.html

How can I prevent the compiler from removing the code I want to 
measure? Is there some utility in the standard library or pragma 
that I should use?

Thanks

AB


More information about the Digitalmars-d-learn mailing list