3

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.

bat.mango
  • 35
  • 7
  • 3
    Do you do much console IO? Microsoft console windows are notoriously slow – sehe May 10 '12 at 12:57
  • The program gives output on what is doing now, but in the time measurements I do only measure the computations, not the 'cout' parts. e.g. '// get timestamp tic3 = rdtsc(); fastCplxConjProd(almost_there, fx, fy, complexLENGTH); toc3 = rdtsc(); t3 = toc3 - tic3; cout << "time taken (in micro sec): " << t3 / cpufreq << "\n\n"; // show the first 10 entries in the output array printArray(almost_there, complexLENGTH, 1); – bat.mango May 10 '12 at 13:04

1 Answers1

1

As per my comment:

Do you do much console IO? Microsoft console windows are notoriously slow

Also look at the ENVIRONMENT variables, notably:

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thank you for the advice. Correct me, if I understood something wrong. I put the libfftw3-3.dll in the System32 folder, which is anyways included in the PATH. It is now found by the system every time I execute the program. That does not give any performance gain. I cannot find a LANG or HOME variable in my environment variables. However, can the settings in those variables explain the performance _difference_ between NetBeans' internal terminal and windows command prompt? – bat.mango May 10 '12 at 14:44
  • @bat.mango: yes and no. I'm not aware of the details of your program. But locale settings can make a performance difference of 20x depending on your task. See also: **[Unix sort command takes much longer depending on where it is executed?! (fastest from ProcessBuilder in program run from IDE, slowest from terminal)](http://stackoverflow.com/questions/7124489/unix-sort-command-takes-much-longer-depending-on-where-it-is-executed-fastest/7150015#7150015)** – sehe May 10 '12 at 15:41
  • Added more detail to answer (PATH ordering, locale and Fusion logging) – sehe May 10 '12 at 15:45
  • thank you for the detailed information and the links to the other questions. I did not find them because I was assuming it is a c++ specific issue. I _#include_ed __ and put the command _global(std::locale("C"));_ at the beginning of the _main()_ function. No performance gain from that. Doesn't that only make a difference for character data? I have only numeric data of type _double_. The difference in computation time also persists. Next, I will check the search PATH sequence. But that will have to wait 'till tomorrow. Cheers! – bat.mango May 10 '12 at 16:04
  • I don't know whether this is embarrassing for me, but the keys for the fusion log do not exist in my registry. Adding them in the _Fusion_ "folder" doesn't do anything when I run the program. It seems I am much too inexperienced with these kinds of things. But as I pointed out earlier the computation that takes actually longer in command prompt than in NetBeans' terminal does not depend on the dll. It is just adding and multiplying numbers. I don't understand why that is slower in windows command prompt. – bat.mango May 11 '12 at 12:04
  • @bat.mango perhaps you should use [process explorer](http://technet.microsoft.com/en-us/sysinternals/bb896653) to compare environment variables between the two processes. You could also explicitely compare the version of runtime libraries used in both instances. – sehe May 11 '12 at 18:46
  • Also, the fusion keys are meant to be absent (they are for debugging). Once you add them, **and make sure the LogPath directory exists** (e.g. `C:\Temp\Fusion` must exist) all dynamic loader/runtime linker activity will be logged in HTML files in subdirectories. (See also the link I added to the answer) – sehe May 11 '12 at 18:47
  • I don't find any traces of my executable in the Fusion log files. However, the only dynamic linked library that is used in my program is not involved in the _crucial_ computation, the multiplication of two arrays `double[2]` of complex numbers that takes about 5 microseonds when run in NetBeans' internal terminal and close to 100 microseconds in a windows console window. Has it anything to do with NetBeans and how environment variables are handled therin? Sorry for my stupid questions, I simply don't understand this. I'll edit my question and include the code of that computation. – bat.mango May 15 '12 at 14:28
  • @bat.mango It seems to me that you might be stressing your assumptions a bit too much ('...is not involved in the crucial computation'). If you drop the assumptions and simply profile the thing, you might find out to your surprise that something like that is unexpectedly cropping up in your benchmark. I'd be more than happy to help out further, but I'd like to see an actual working program so I can run it under a profiler myself. – sehe May 15 '12 at 15:52
  • Thank you for the kind offer and all the effort you have already put in helping me. I'd be glad to provide you with the source code (the complete NetBeans project). If you could contact me via email (schuller^AT^orn.mpg.de) I can send you a download link for a .rar file containing the project files (I think posting the whole code would rather blow the post up unnecessarily). Thank you very much. – bat.mango May 16 '12 at 11:54
  • Regarding the differences in the two processes, I used process explorer to identify the libraries that are involved in running the executable in NetBeans' internal terminal and in the Windows command prompt. There is no difference in the involved libraries and all of them (except the libfft3-3.dll) are already loaded before the the executable is run. Was this, what the advice was meant to mean? – bat.mango May 16 '12 at 11:57
  • 1
    @bat.mango: Libraries was one aspect to check. "already loaded before the executable is run" would be a _contradictio in terminis_, or you might mean _not delay-loaded_? Also, check differences in the environment and open file handles. Open file handles might indicate differences in e.g. the wisdom files used by FFTW (if any). In other words, apply maximum scrutiny. I would still like to see a working sample program – sehe May 16 '12 at 14:30