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

Speed-Tests with Neural Network Calculations


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

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

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

With smaller Numbers the effect is even stronger.

--- Code: ---%Input=300

--- End code ---

I need 66 Tix for MAT and 24 Tix with the FOR-Loop. MAT is slower anyway.
--- Code: ---%Input=30
 ? 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
 ? 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%.


[0] Message Index

Go to full version