IT-Berater: Theo Gottwald (IT-Consultant) > Low Level Code Optimization

Speed-Tests with Neural Network Calculations

(1/1)

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



--- Code: ---%Input=3000
%hidA=30000

REGISTER R01 as Long, R02 as Long
tix Q1
#if 0
MAT Hidi()=wi()*InpN()
#else
For R01=1 to %hidA
Hidi(R01)=0
  For R02=1 to %Input
    Hidi(R01)+=wi(R01,R02)*InpN(R02)
  next
next r02
#endif
 tix END Q1
 ? STR$(int(Q1/100000))
--- End code ---

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

--- Code: ---%Input=300
%hidA=600

--- End code ---

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

--- End code ---
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?


--- Code: ---%Input=300
%hidA=600
...
 ? STR$(int(Q1/100000))

--- End code ---

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%.

Navigation

[0] Message Index

Go to full version