In a different thread: http://www.vbforums.com/showthread.p...29#post4486929
(which became a bit too OffTopic) this VB6-code-snippet here was posted by Niya:
and compared against a C++ compiled snippet:
With the following timing-results:
VB Time: 3925.62500000349
C++ Time: 424.406250000175
And thus suggesting, that the C++ code runs about factor 9 faster.
My experience with the VB6-native compiler is a different one, being in most "real world calculations"
only about 10% slower compared with VC6 (when using basically the same inner loops).
Well, in the above VB-code-snippet the Var-Declaration for i was omitted (deliberately?)
and which therefore was treated as a Variant-type - but Ok, I measured the VB6-performance
(native compiled, all extended options checked) for "loop-variable i in Variant-mode" and got:
2820msec
Then I've fixed the VB-code snippet, declaring Variable 'i' explicitely as Long and compiled again and running it got:
343msec
So the correctly typed VB6-code was now performing about factor 8 faster
That's close enough to the factor 9 the C-code was outperforming the incorrectly typed VB-version ... and 9/8 = 1.12...
so that also matches with the above already mentioned ~10% performance-advantage a C-compiler usually (only) gains on VB6-native-binaries.
Below is the correctly typed VB6-code which produced the 343msec on my machine.
Olaf
(which became a bit too OffTopic) this VB6-code-snippet here was posted by Niya:
Code:
Private Sub DoTestVB()
Dim numElements As Long
Dim numbers() As Long
Dim x As Long
numElements = 10000
ReDim numbers(1 To numElements)
For x = 1 To numElements
For i = 1 To numElements
numbers(i) = i * 100
Next
Next
End Sub
Code:
void _stdcall DoTestC()
{
int numElements = 10000;
int* numbers;
numbers=new int[numElements];
for(int x=0;x<numElements;x++)
{
for(int i=0;i<numElements;i++)
{
numbers[i]=i*100;
}
}
delete numbers;
}
VB Time: 3925.62500000349
C++ Time: 424.406250000175
And thus suggesting, that the C++ code runs about factor 9 faster.
My experience with the VB6-native compiler is a different one, being in most "real world calculations"
only about 10% slower compared with VC6 (when using basically the same inner loops).
Well, in the above VB-code-snippet the Var-Declaration for i was omitted (deliberately?)
and which therefore was treated as a Variant-type - but Ok, I measured the VB6-performance
(native compiled, all extended options checked) for "loop-variable i in Variant-mode" and got:
2820msec
Then I've fixed the VB-code snippet, declaring Variable 'i' explicitely as Long and compiled again and running it got:
343msec
So the correctly typed VB6-code was now performing about factor 8 faster
That's close enough to the factor 9 the C-code was outperforming the incorrectly typed VB-version ... and 9/8 = 1.12...
so that also matches with the above already mentioned ~10% performance-advantage a C-compiler usually (only) gains on VB6-native-binaries.
Below is the correctly typed VB6-code which produced the 343msec on my machine.
Code:
Option Explicit
Private Sub Form_Click()
Dim T As Single
T = Timer
DoTestVB
Caption = Format((Timer - T) * 1000, "0.000msec")
End Sub
Private Sub DoTestVB()
Dim x As Long, i As Long
Dim numElements As Long, numbers() As Long
numElements = 10000
ReDim numbers(0 To numElements - 1)
For x = 0 To numElements - 1
For i = 0 To numElements - 1
numbers(i) = i * 100
Next
Next
End Sub