• Welcome to Jose's Read Only Forum 2023.

## Speed-Tests with Neural Network Calculations

Started by Theo Gottwald, February 07, 2018, 08:08:09 AM

0 Members and 1 Guest are viewing this topic.

#### Theo Gottwald

The First Test is done with SINGLE Precision, it compares the
MAT - Statement with conventional Loops. The result is surprising.

`%Input=3000%hidA=30000REGISTER R01 as Long, R02 as Longtix Q1#if 0MAT Hidi()=wi()*InpN()#elseFor R01=1 to %hidAHidi(R01)=0  For R02=1 to %Input    Hidi(R01)+=wi(R01,R02)*InpN(R02)  nextnext r02#endif tix END Q1 ? STR\$(int(Q1/100000))`

I get 68057 for the FOR-Loop.
And 79259 for the MAT Statement.
MAT is SLOWER.

With smaller Numbers the effect is even stronger.
Using
`%Input=300%hidA=600`

I need 66 Tix for MAT and 24 Tix with the FOR-Loop. MAT is slower anyway.
Using `%Input=30%hidA=60... ? STR\$(int(Q1/1000))`
I need again 66 Tix for MAT and 24 Tix with the FOR-Loop. MAT is generally slower here.

Now switching to Extended-Datatype. Does it change?

MAT uses 73 Tix, the For-Loop just 36 Tix. So what we see is that Extended is 50 slower then SINGLE using a FOR-Loop, but still faster then MAT using SINGLE.

Let's try Double. It comes with 67 Tix for MAT and 22 with the FOR-Loop. So no big difference to SINGLE anymore.
And with higher numbers?

`%Input=300%hidA=600... ? STR\$(int(Q1/100000))`

We get 26 with the FOR-Loop and we get 72 with MAT.
With SINGLE it was 24/66.
With EXTENDED it was 46/83

It shows that modern CPU's do not have substancial advantages using SINGLE anymore.
Just use DOUBLE. While EXTENDED ist still a bit more costly.
Unless you use MAT then its not such a large difference.

Conclusion: For simple MATRIX-Multiplication with 1-dimensional Vectors, MAT is slower then a conventional FOR-Loop by amazing 50%.