AliasSeq seems to compile slightly faster with static foreach
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Jan 8 15:37:01 UTC 2018
On Sun, Jan 07, 2018 at 07:20:44PM -0700, Jonathan M Davis via Digitalmars-d wrote:
[...]
> LOL. Okay, I feel like an idiot now. Switching to static foreach
> resulted in a slight speed-up, and then switching to only resulted in
> a very large speed-up. However, it turns out that the main reason that
> I got the speed-up that I did with only was because I screwed up.
>
> In a number of places, I was using only by itself, but in a bunch of
> places, I was using only with lockstep and iota so that I could have
> indices, and I screwed up with the iota call. I misremembered how iota
> worked with a single argument; I thought that iota(0) created an
> infinite range, whereas it creates a zero-length range. Once I fixed
> it so that it was iota(size_t.max), it was actually slightly slower
> than using array literals. So, while I definitely got a speed-up by
> switching away from using normal foreach with AliasSeq, ultimately,
> the really large speed-up I got by switching to only was because I was
> accidentally not even compiling in large sections of test code. :|
[...]
This is why sometimes I deliberately modify a unittest to make it fail,
just so I'm sure that the code is actually being run. :-P There's been
at least one incident where I wrote a whole bunch of unittests and
thought my code was OK because there was no runtime error, only to
discover that it was only because I forgot to specify -unittest on the
compiler command line. :-/
Or in another incident, the unittest was inside a template, and I had
protected it with a static if on a specific combination of template
arguments so that it will only be instantiated once, but then it turned
out that that one instantiation never actually happened.
T
--
Guns don't kill people. Bullets do.
More information about the Digitalmars-d
mailing list