in not working for arrays is silly, change my view

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Mar 2 23:46:54 UTC 2020


On Mon, Mar 02, 2020 at 06:27:22PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:
[...]
> Yeah, this looked very fishy to me. ldc can do some nasty "helpful"
> things to save you time! When I posted my results, I was using DMD.
> 
> I used run.dlang.io with ldc, and verified I get the same (similar)
> result as you. But searching through 5 billion integers can't be
> instantaneous, on any modern hardware.
[...]

Beware that LDC's over-zealous optimizer can sometimes elide an entire
function call tree if it determines that the return value is not used
anywhere.  I've also observed that it can sometimes execute the entire
function call tree at compile-time and emit just a single instruction
that loads the final result.

So, always check the assembly output so that you're sure the benchmark
is actually measuring what you think it's measuring.

To prevent the optimizer from eliding "useless" code, you need to do
something with the return value that isn't trivial (assigning to a
variable that doesn't get used afterwards is "trivial", so that's not
enough). The easiest way is to print the result: the optimizer cannot
elide I/O.


T

-- 
Freedom: (n.) Man's self-given right to be enslaved by his own depravity.


More information about the Digitalmars-d-learn mailing list