VB,Java,Fortran or C?
Hi
I did a very simple loop in all these languages in order to test which was fastest. The i-loop contained:
i=1 to 500,000,000(that's 5e8)
x=x+i
y=x/i
z=i^30
next i
Not a particularly brilliant test, but I couldn't find any benchmarking programs on the web, and I only really know VB and Java. Anyway, the speeds in seconds for this loop where:
Visual Basic: 314 seconds (i.e. over 5 mins!)
Java: 37 secs
Fortran: 29 secs but 5 secs when optimised
C: 6 secs but less than 2 secs when optimised
The code for these is shown at the end.
I have a 4000 line code in VB, but it takes forever to run (I leave it overnight, but it's still not enough). There's no graphics or anything - just simulating trading on 10 years worth of stock price data, which does not involve anything particularly complex (arrays, if-statements, simple maths, and a bit of sorting - just I do it all a few thousand times).
I'm now thinking of converting it all into C because, according to that simple test, VB is over 150 times slower than C, though I'd really rather do it in Java and introduce my colleagues to the benefits of Java (got this job about six months ago, sort of my first programming job). In a previous discussion (that Why is Java slow? with about 160 replies), someone said VB was only 50% slower than C, and 75% slower than Java, but then someone else said VB could be done faster than Java?
Does anyone out there know of any proper benchmarking tests I can run, and if in "proper" programs VB is really that bad when compared to C, and is it possible to get Java down to a speed close to C if all it's doing is mostly just maths and no graphics? Basically, is it worth my while converting it in the first place, and will it be just as fast in Java as in C and save me the bother of learning C?
Any pointers to further info where speed tests like these have been performed, or any light you can shed on this matter, would be greatly appreciated.
Cheers,
Gregory.
Code Tests
-
VB was version 6.0
Java was latest 1.3.1 jdk
Fortan77 and C used the gnu compilers (from www.cygwin.com)
Machine: 1GHz Pentium III running Windows NT 4.0
***VB
Private Sub Command1_Click()
Dim i As Long
Dim x As Double
Dim y As Double
Dim z As Double
x = 0#
y = 0#
z = 0#
For i = 1 To 500000000
x = x + i
y = x / i
z = i ^ 30
Next i
frmMain.Caption = "Finished, x = " & x
End Sub
***Java
public class speed_test{
public static void main(String args[]){
double x=0.0;
double y=0.0;
double z=0.0;
for(int i=0; i<500000000; i++){
x=x+i;
y=x/i;
z=i^30;
}
System.out.println("Finished, x = " + x);
}
}
***FORTRAN77
program speed_test
integer i
double precision x, y, z
x=0.0
y=0.0
z=0.0
do 20 i=1, 500000000
x=x+i
y=x/i
z=i**30
20continue
write(6,*)"Finished, x = ", x
stop
end
***C
main () {
int i;
double x;
double y;
double z;
x=0.0;
y=0.0;
z=0.0;
for(i=0; i<500000000; i++)
x=x+i;
y=x/i;
z=i^30;
printf("Finished, x = %f\n", x);
}

