in not working for arrays is silly, change my view
something at something.com
Tue Mar 3 00:32:59 UTC 2020
On Monday, 2 March 2020 at 23:27:22 UTC, Steven Schveighoffer
> What I think is happening is that it determines nobody is using
> the result, and the function is pure, so it doesn't bother
> calling that function (probably not even the lambda, and then
> probably removes the loop completely).
> I'm assuming for some reason, the binary search is not flagged
> pure, so it's not being skipped.
Apparently you're right:
> If I change to this to ensure side effects:
> bool makeImpure; // TLS variable outside of main
> auto results = benchmark!(
> () => makeImpure = r1.canFind(max),
> () => makeImpure = r2.contains(max),
> () => makeImpure = r3.canFind(max),
> writefln("%(%s\n%)", results); // modified to help with the
> comma confusion
> I now get:
> 4 secs, 428 ms, and 3 hnsecs
> 221 μs and 9 hnsecs
> 4 secs, 49 ms, 982 μs, and 5 hnsecs
> More like what I expected!
Ahhhh damn! And here I was thinking that branch prediction made a
HUGE difference! Ok, I'm taking my tail and slowly moving away
now :) Let us never speak of this again.
More information about the Digitalmars-d-learn