B
Bas
Hello,
Until 6 years ago I was a C++ programmer. The last 6 years I've done
something else than computerprogramming, but now I'm a bit back, learning
myself C#.
I cannot resist sometimes to compare these two languages (as far as I can,
not programming for 6 years is quitte a time),
so I had to try the speed of both: allocate 30,000,000 objects of a class,
and clocking the time necessary.
Here is the code for C#:
namespace Temp
{
class Program
{
static void Main(string[] args)
{
DateTime t1 = DateTime.Now;
Test[] tab = new Test[30000000];
for (long i = 0; i< 30000000; i++) {
tab=new Test();
}
DateTime t2 = DateTime.Now;
Console.Write("Begin time is {0}:{1}:{2}:{3}\n", t1.Hour, t1.Minute,
t1.Second, t1.Millisecond);
Console.Write("End time is {0}:{1}:{2}:{3}\n", t2.Hour, t2.Minute,
t2.Second, t2.Millisecond);
Console.Read();
}
}
class Test{
private int i;
private double d;
private float x;
public Test(){
i=123;
d=3.1415926;
x=6.28f;
}
}
}
and here it is for C++:
#include "stdafx.h"
#include <windows.h>
class Test {
private:
int i;
double d;
float fl;
public:
Test() {i = 123; d = 3.1415926; fl = 6.28f; }
};
int _tmain(int argc, _TCHAR* argv[])
{
SYSTEMTIME startingtime, endtime;
GetLocalTime(&startingtime);
Test *ar[30000000];
for(long int j = 0; j< 30000000; j++)
ar[j] = new Test;
GetLocalTime(&endtime);
printf("%2d:%2d:%2d:%2d\n",startingtime.wHour,startingtime.wMinute,startingtime.wSecond,startingtime.wMilliseconds);printf("%2d:%2d:%2d:%2d\n",endtime.wHour,endtime.wMinute,endtime.wSecond,.wMilliseconds); getchar(); return 0;}I hope someone will say "YOU MORON..!"and that I've done something wrong..But the C# program was ready within 11seconds.. the C++ program took 15seconds; so it was SLOWER.How can thisbe!?!?Kind regards,Bas from Holland
Until 6 years ago I was a C++ programmer. The last 6 years I've done
something else than computerprogramming, but now I'm a bit back, learning
myself C#.
I cannot resist sometimes to compare these two languages (as far as I can,
not programming for 6 years is quitte a time),
so I had to try the speed of both: allocate 30,000,000 objects of a class,
and clocking the time necessary.
Here is the code for C#:
namespace Temp
{
class Program
{
static void Main(string[] args)
{
DateTime t1 = DateTime.Now;
Test[] tab = new Test[30000000];
for (long i = 0; i< 30000000; i++) {
tab=new Test();
}
DateTime t2 = DateTime.Now;
Console.Write("Begin time is {0}:{1}:{2}:{3}\n", t1.Hour, t1.Minute,
t1.Second, t1.Millisecond);
Console.Write("End time is {0}:{1}:{2}:{3}\n", t2.Hour, t2.Minute,
t2.Second, t2.Millisecond);
Console.Read();
}
}
class Test{
private int i;
private double d;
private float x;
public Test(){
i=123;
d=3.1415926;
x=6.28f;
}
}
}
and here it is for C++:
#include "stdafx.h"
#include <windows.h>
class Test {
private:
int i;
double d;
float fl;
public:
Test() {i = 123; d = 3.1415926; fl = 6.28f; }
};
int _tmain(int argc, _TCHAR* argv[])
{
SYSTEMTIME startingtime, endtime;
GetLocalTime(&startingtime);
Test *ar[30000000];
for(long int j = 0; j< 30000000; j++)
ar[j] = new Test;
GetLocalTime(&endtime);
printf("%2d:%2d:%2d:%2d\n",startingtime.wHour,startingtime.wMinute,startingtime.wSecond,startingtime.wMilliseconds);printf("%2d:%2d:%2d:%2d\n",endtime.wHour,endtime.wMinute,endtime.wSecond,.wMilliseconds); getchar(); return 0;}I hope someone will say "YOU MORON..!"and that I've done something wrong..But the C# program was ready within 11seconds.. the C++ program took 15seconds; so it was SLOWER.How can thisbe!?!?Kind regards,Bas from Holland