I am new in this forum, so excuse me if I am not asking the question right the first time. I think it is not necessary to provide code here since I think it has nothing to do with the code and the question might be more general.
I have written and built a C++ project in NetBeans 7.1.2 using MinGW (g++) in Windows XP. Both, the Debug version and the Release version work fine and deliver the desired output of the computations. However, if I "run" the project (either project) in NetBeans' internal terminal, I can measure computation times of between 115 and 130 microseconds. If I execute the exe file in a Windows command prompt, I measure computation times of between 500 and 3000 microseconds. (On a 2.2 GHz Intel Core 2 Duo with 2 GB Ram. I measure the time by reading the number of cpu clock ticks since reset and dividing by the cpu frequency.)
I tried the same on another computer (incl. building the project), also 2.2 GHz and 16 GB Ram and Windows7. The program runs a bit faster, but the pattern is the same. The same is true, when I run the project from NetBeans but in an external terminal (also windows terminal). And it applies to both versions, the debug and the release version.
One of the computations (not the most time critical) is a Fast Fourier Transform and depends on the fftw (http://www.fftw.org/) "libfftw3-3.dll" library. Within NetBeans its location is known, in the windows command prompt, the dll has to be in the same directory as the executable.
Why is it, that a program runs so much faster in NetBeans' internal terminal window than in a windows command prompt window?
Could it have something to do with the dynamic linking of the library at load time?
However, the computation step that actually takes longer in windows command prompt than in NetBeans' terminal does not depend on the functions in the dll (the multiplication of two comlex numbers).
The most time consuming and crucial computation in the program is the multiplication of two arrays of complex number of type fftw_complex
which is double[2]
:
for(int i = 0; i < n; ++i) {
double k1 = x[i][0] * (y[i][0] - y[i][1]);
double k2 = (y[i][1] * -1) * (x[i][0] + x[i][1]);
double k3 = y[i][0] * (x[i][1] - x[i][0]);
result[i][0] = k1 - k2;
result[i][1] = k1 + k3;
}
x
and y
are two arrays of complex numbers where [i][0]
holds the real part and [i][1]
holds the imaginary part. result
is a preallocated array of the same type.
This loop takes about 5 microseconds for arrays of length 513 when the program is executed in NetBeans' internal terminal, but rather 100 microseconds when I run the program in a Windows command prompt. I could not find an explanation in all the really helpful advice in the answer by sehe.
Please let me know, if you think it has something to do with the actual code, then I would provide some.
I have looked for similar questions, but could not find any. Any hints or points to other questions and answers that I might have missed are appreciated. Cheers.