Tim Anderson
2003-12-29 13:37:24 UTC
Did some playing around with this.
Sorry, my tests were in C# as I'm more concerned at the moment with .Net
perf rather than D8 perf; but it is all relevant.
First result: D8 about 39K ticks, C# about 6.5K ticks. Suggests some
specific Delphi problem here.
Now some experiments.
Point 1: .Net always allocates arrays on the heap. Stack is quicker. So
instead of arrays I used a struct with 16 float members:
struct TStackMatrix
{
public float XW;
public float XX;
public float XY;
etc;
Result: C# about 2.5K ticks. A lot faster.
Note I'm not saying you should do arrays like this. However, it's one thing
to say ".Net is slow", another thing to say, ".Net arrays are slow because
they are allocated on the heap".
Point 2: Use a procedure instead of a function, passing the result variable
by reference.
Result: C# about 1K ticks. About twice as fast again.
Point 3: Delphi 7 has an optimizer. Do we know how it is optimizing this
code? Well, it can be tested by decompiling the exe. But it's interesting to
turn D7's optimizer off.
Result: D7 about 1.7K ticks. Now slower than C#.
If I have time, I'll poke about with the D8 code too.
Tim
Borland execs speak:
http://www.itwriting.com/borlandtop.php
Sorry, my tests were in C# as I'm more concerned at the moment with .Net
perf rather than D8 perf; but it is all relevant.
First result: D8 about 39K ticks, C# about 6.5K ticks. Suggests some
specific Delphi problem here.
Now some experiments.
Point 1: .Net always allocates arrays on the heap. Stack is quicker. So
instead of arrays I used a struct with 16 float members:
struct TStackMatrix
{
public float XW;
public float XX;
public float XY;
etc;
Result: C# about 2.5K ticks. A lot faster.
Note I'm not saying you should do arrays like this. However, it's one thing
to say ".Net is slow", another thing to say, ".Net arrays are slow because
they are allocated on the heap".
Point 2: Use a procedure instead of a function, passing the result variable
by reference.
Result: C# about 1K ticks. About twice as fast again.
Point 3: Delphi 7 has an optimizer. Do we know how it is optimizing this
code? Well, it can be tested by decompiling the exe. But it's interesting to
turn D7's optimizer off.
Result: D7 about 1.7K ticks. Now slower than C#.
If I have time, I'll poke about with the D8 code too.
Tim
Borland execs speak:
http://www.itwriting.com/borlandtop.php