On Thursday, 7 April 2016 at 08:33:40 UTC, Andrea Fontana wrote:
On Thursday, 7 April 2016 at 08:23:09 UTC, John Colvin wrote:
But it definitely can eliminate an unused result. My
prediction: you took an array and sorted it, then did nothing
with the result, so it rightly concluded that there was no
point doing the sort. In any given case the compiler could be
removing some or all of the work.
But it should remove result if I replace boolSort() with sort()
too, instead it take 10 seconds to run.
Not necessarily. It totally depends on the implementation details
and the exact way the optimiser works. It might be interesting
and informative for you to explore exactly why a particular
version of a particular compiler with particular compilation
flags will inline and elide one sort function but not another,
but I would recommend just not letting the compiler see the
source code of the benchmark and the sorting at the same time*,
then you know neither will be inlined and also no extra
attributes will be inferred and unrealistically taken advantage
of.
*hench my example of compiling one module to an object file and
then compiling the other and linking them, without ever importing
one from the other.