in not working for arrays is silly, change my view

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Mar 3 01:07:59 UTC 2020


On Mon, Mar 02, 2020 at 07:51:34PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:
[...]
> On 3/2/20 6:46 PM, H. S. Teoh wrote:
> > 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.
> 
> Yeah, well, that means you are also benchmarking the i/o (which would
> dwarf the other pieces being tested).

Not necessarily.  Create a global variable whose sole purpose is to
accumulate the return values of the functions being tested, then return
its value as the return value of main().  The optimizer is bound by
semantics not to elide anything then.


> I think assigning the result to a global fits the bill pretty well,
> but obviously only works when you're not inside a pure function.
[...]

A sufficiently-advanced optimizer would notice the global isn't referred
to anywhere else, and therefore of no effect, and elide it anyway.  Not
saying it actually would, 'cos I think you're probably right, but I'm
leaving nothing to chance when the LDC optimizer is in question. :-P


T

-- 
It only takes one twig to burn down a forest.


More information about the Digitalmars-d-learn mailing list