I have written the following code and compiled it on 3 different compilers (pardon the probably terrible coding, still learning here). Each executable runs very differently from each other in terms of speed. Here are my results when run 50,000 times. The results are very interesting. Also apologies if this is too complicated for the beginner forums, wasn't sure where to post.
The computer these are being compiled and ran:
Windows 7 Pro 64-bit 6.1.7600
Intel C2D E6600 @ 3.2Ghz
6GB DDR2-800 RAM
Visual C++ Express:
Compiled under default "Release" settings.
Compiler Options: /O2 /Oi /GL /D "_MBCS" /FD /EHsc /MD /Gy /Fo"Release\\" /Fd"Release\vc90.pdb" /W3 /nologo /c /Zi /TP /errorReport:prompt
Total Run Time: 45.331
Average of 1103 runs per second.
Dev-C++:
Latest MinGW install (3.4.5 mingw-vista special r3).
Compiler Options: -fexpensive-optimizations -O3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -s
Total Run Time: 11.427
Average of 4375.6 runs per second.
Linux GCC (g++):
Ubuntu 9.10 - Latest update @ 3/27/2010.
GCC (g++) version 4.4.1-4ubuntu9
Compiler Options: g++ whileLoop.cpp -o whileLoop
Total Run Time: 0.06
Average of 600,000-800,000 runs per second.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
double a, timez;
int RunAmount;
double avgTimePer1kRun;
a = 1;
clock_t start, end, updatedTime;
cout << "Hello, please type a number: ";
cin >> RunAmount;
start = clock();
while(a <= RunAmount)
{
updatedTime = clock();
cout << "Current Run #: " << a << endl;
a = ++a;
}
end = clock();
timez = (double(end)-double(start))/CLOCKS_PER_SEC;
cout << "Total Run Time: " << timez << endl;
avgTimePer1kRun = RunAmount/timez;
cout << "Average of " << avgTimePer1kRun << " runs per second.";
return 0;
}
|
I was interested in doing some kind of benchmark just to see if I could, then decided I should test the compilers while I was at it. I am not sure what is causing the massive differences between the three. I am sure there are some compiler optimizations that I could turn on/off and get different results however I have already tried on the slower two. Any comments would be really cool.