Performance of tables slower than built in?
Basilez B.
b2.temp at gmx.com
Fri May 24 08:13:00 UTC 2019
On Thursday, 23 May 2019 at 10:16:42 UTC, Alex wrote:
> On Wednesday, 22 May 2019 at 08:25:58 UTC, Basile B. wrote:
>> On Wednesday, 22 May 2019 at 00:22:09 UTC, JS wrote:
>>> I am trying to create some fast sin, sinc, and exponential
>>> routines to speed up some code by using tables... but it
>>> seems it's slower than the function itself?!?
>>>
>>> [...]
>>
>> Hi, lookup tables ARE faster but the problem you have here,
>> and I'm surprised that nobody noticed it so far, is that YOUR
>> SWITCH LEADS TO A RUNTIME STRING COMPARISON AT RUNTIME. Just
>> replace it with a static if (Method = "Linear") { /*...*/}
>> else { /*...*/}
>>
>> Also takes care to the type used. With DMD the implicit
>> coercion of float and double can lead to extra conversions.
>>
>> You'll directly see a 15% gain after refactoring the switch.
>
> Surely not?!?! Surely the compiler can optimize that switch
> since the value passed is CT? I thought the whole point of not
> having static switch(analogous to static if) was because it
> would go ahead and optimize these cases for us... and it's just
> a switch, just a jmp table.
Try by yourself but to be clear note that I don't like your
attitude, which I find disrespectful. I'm just here to help, I
explained you the big problem you have in your code and you start
discussing something that's not to be discussed AT ALL. Look at
this https://d.godbolt.org/z/vtzVdp, in sinTab you'll be able to
see
call pure nothrow @nogc @safe int
object.__switch!(immutable(char), "Linear",
"Constant").__switch(scope const(immutable(char)[]))@PLT
and this even with LDC2 -O3. That's why your LUT is so slow.
refactor the switch with "static if", the branch will be
eliminated and you'll to see the perf improvement.
More information about the Digitalmars-d-learn
mailing list