Moving up from Fortran, I needed to determine which modern development
language/platform generated the faster (fastest will vary according to
application, code design, and useage) compiled floating point-intensive
programs.
Apparently, VB5.0 using the new, optimzing compiler is nowhere as good
as Microsoft keeps saying it is -- just a 2x performance increase over
VB5.0 P-code.
However, Delphi is suprising for it's great performance right out of
the box! Almost as fast as VC 5.0, and probably an easier development
environment to start with.
Here's the figures:
1000x1000 array
VC 5.0 Delphi 3.0 Lahey ELF90 VB 5.0 Optimzed VB 5.0 P-code
1st run:5(4) 5(4) 8(6) 13(10) 24(20) seconds
2nd run:4(3) 5(4) 8(6) 13(10) 24(19)
1500x1500 array
VC 5.0 Delphi 3.0 Lahey ELF90 VB 5.0 Optimzed VB 5.0 P-code
1st run:9(8) 10(9) 17(13) 30(23) 60 seconds
2nd run:9(8) 9(9) 17(13) 29(22) 60
The first number of pairs of numbers is the time from when the program
was told to start running the subroutine, until it finished (ie. total
time including array setup time). The second number was the time
actually spend in the array calculation loop itself (run time). Thus,
subtracting (total time) - (run time) = (overhead time), in general.
Either using program coded timers or stopwatch.
The 1st run are times for the first time the program was launched and
executed. The 2nd run is for the second time the program was asked to
run it again right after the 1st run (taking into some account overhead
due to setting up memory and program caching).
Cyrix 6x86, 512KB cache, 32MB ram, 2.0GB EIDE, 1280x1024 Diamond
Stealth 3000 3D 4MB, Windows 95, Ethernet networked, desktop image, a
couple handy Windows TSRs loaded (eg. VSCAN), but generally nothing else
running from a clean start.
David =)
Delphi 3.0 code-------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, Math;
type
TForm1 = class(TForm)
Start: TButton;
MyMemo: TMemo;
procedure StartClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{$M 10000000,10000000}
procedure TForm1.StartClick(Sender: TObject);
var myArray : array [1..1000,1..1000] of double;
StartTime, EndTime : TDateTime;
k,j : integer;
begin
for k := 1 to 1000 do
for j := 1 to 1000 do
myArray[k,j] := Random * 1000;
StartTime := Time;
for k := 1 to 1000 do
for j := 1 to 1000 do
myArray[k,j] := myArray[j,k] * myArray[k,j] - myArray[j,1001-j]
/ myArray[k,1001-k] * Log2(Random) / (Random + myArray[1001 -j,k]);
EndTime := Time;
MyMemo.Lines.Add ('Start Time: ' + TimeToStr(StartTime) + ' End
Time: ' + TimeToStr(endTime));
end;
end.
VC 5.0 code----------
#include <float.h>
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
double myArray[1500][1500];
void main( int argc, char *argv[] )
{
char tmpbuf[128];
_tzset();
_strtime( tmpbuf );
printf( "begin here - OS time:\t\t\t\t%s\n", tmpbuf );
srand( (unsigned)time( NULL ) );
int k,j;
for (k = 0; k < 1501; k++)
for (j = 0; j < 1501; j++)
myArray [k][j] = rand() * 1000;
_strtime( tmpbuf );
printf( "start OS time:\t\t\t\t%s\n", tmpbuf );
for (k = 0; k < 1501; k++)
for (j = 0; j < 1501; j++)
myArray[k][j] = myArray[j][k] * myArray[k][j] - myArray[j][1501-j] /
myArray[k][1501-k] * log(rand()) / (rand() + myArray[1501-j][k]);
_strtime( tmpbuf );
printf( "end OS time:\t\t\t\t%s\n", tmpbuf );
Fortran code -------------
! ~ 5 seconds using Lahey's free EL-F90 DOS compiler
! - This compiler does not make optimizations!
program Test
implicit none
real :: MyArray(1000,1000)
integer :: k,j
real :: rnd, rnd2
do k = 1,1000
do j = 1,1000
call RANDOM_NUMBER ( Harvest = rnd)
myArray(k,j) = rnd * 1000
end do
end do
write (*,*) " Starting "
do k = 1,1000
do j = 1,1000
call RANDOM_NUMBER ( Harvest = rnd )
call RANDOM_NUMBER ( Harvest = rnd2 )
myArray(k,j)=myArray(j,k)*myArray(k,j)-myArray(j,1001-j) /
myArray(k,1001-k)*Log(rnd) / (rnd2 + myArray(1001-j,k))
end do
end do
write (*,*) " Stopping "
stop
end program Test
Basic code--------
Private Sub StartButton_Click()
dim myArray(1000,1000) as double
dim StartTime
dim EndTime
Dim k,j as integer
for k = 1 to 1000
for j = 1 to 1000
myArray(k,j) = rnd*1000
next j
next k
starttime = time
for k = 1 to 1000
for j = 1 to 1000
myArray(k,j) = myArray(j,k) * myArray(k,j) -
myArray(j,1001-j)/MyArray(k,1001-k) * log(rnd)/(rnd + myArray(1001-j,k)
next j
next k
EndTime = time
MyTextBox.Text = "Start Time: " + str(StartTime) + " End Time: " +
str(EndTime)
End Sub
----------------------------------------------------------