how to benchmark pure functions?

Imperatorn johan_forsberg_86 at hotmail.com
Thu Oct 27 18:20:10 UTC 2022


On Thursday, 27 October 2022 at 17:17:01 UTC, ab wrote:
> 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

Sorry, I don't understand what you're saying.

The examples work for me. Can you provide an exact code example 
which does not work as expected for you?


More information about the Digitalmars-d-learn mailing list