[英]Why does a project “run” faster in NetBeans internal terminal than in windows command prompt?
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. 我在Windows XP中使用MinGW(g ++)在NetBeans 7.1.2中编写并构建了一个C ++项目。 Both, the Debug version and the Release version work fine and deliver the desired output of the computations.
Debug版本和Release版本都可以正常工作,并提供所需的计算输出。 However, if I "run" the project (either project) in NetBeans' internal terminal, I can measure computation times of between 115 and 130 microseconds.
但是,如果我在NetBeans的内部终端中“运行”项目(任一项目),我可以测量115到130微秒之间的计算时间。 If I execute the exe file in a Windows command prompt, I measure computation times of between 500 and 3000 microseconds.
如果我在Windows命令提示符下执行exe文件,我测量的计算时间在500到3000微秒之间。 (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.)
(在带有2 GB Ram的2.2 GHz Intel Core 2 Duo上。我通过读取自复位后的cpu时钟周期数除以cpu频率来测量时间。)
I tried the same on another computer (incl. building the project), also 2.2 GHz and 16 GB Ram and Windows7. 我在另一台计算机(包括构建项目),2.2 GHz和16 GB Ram和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).
当我从NetBeans运行项目但在外部终端(也是Windows终端)时也是如此。 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. 其中一个计算(不是最关键的时间)是快速傅立叶变换,它依赖于fftw( http://www.fftw.org/ )"libfftw3-3.dll“库。 Within NetBeans its location is known, in the windows command prompt, the dll has to be in the same directory as the executable.
在NetBeans中,其位置是已知的,在Windows命令提示符下,dll必须与可执行文件位于同一目录中。
Why is it, that a program runs so much faster in NetBeans' internal terminal window than in a windows command prompt window? 为什么一个程序在NetBeans的内部终端窗口中比在Windows命令提示符窗口中运行得快得多?
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). 但是,在Windows命令提示符中实际需要比在NetBeans终端中实际需要更长时间的计算步骤不依赖于dll中的函数(两个复合数字的乘法)。
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]
: 程序中最耗时和最关键的计算是两个复数
fftw_complex
数组的乘法,它是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. x
和y
是两个复数数组,其中[i][0]
保持实部, [i][1]
保持虚部。 result
is a preallocated array of the same type. result
是一个相同类型的预分配数组。
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. 当程序在NetBeans的内部终端中执行时,对于长度为513的数组,此循环大约需要5微秒,而在Windows命令提示符下运行程序时则为100微秒。 I could not find an explanation in all the really helpful advice in the answer by sehe.
在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.
干杯。
As per my comment: 根据我的评论:
Do you do much console IO?
你做了很多控制台IO吗? Microsoft console windows are notoriously slow
微软的控制台窗口非常慢
Also look at the ENVIRONMENT variables, notably: 另请参阅ENVIRONMENT变量,特别是:
PATH 路径
Defines search paths. 定义搜索路径。 The ordering of search locations may influence load times .
搜索位置的排序可能会影响加载时间 。 To really get a handle on what is being done, consider enabling the fusion log:
要真正掌握正在完成的工作,请考虑启用融合日志:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Fusion] "ForceLog"=dword:00000001 "LogFailures"=dword:00000001 "LogPath"="C:\\\\Temp\\\\Fusion"
(See How to enable assembly bind failure logging (Fusion) in .NET for important hints) (有关重要提示,请参阅如何在.NET中启用程序集绑定失败日志记录(Fusion) )
This will provide you with detailed information of what locations were searched, and in what order. 这将为您提供搜索位置的详细信息以及顺序。
LANG LANG
Might override the system locale (try setting the locale to C from your code) 可能会覆盖系统区域设置(尝试从您的代码中将区域设置设置为C)
For an explanation of the thinking behind the locale settings, see Unix sort command takes much longer depending on where it is executed?! 有关语言环境设置背后思考的解释,请参阅Unix sort命令需要更长的时间,具体取决于它的执行位置?! (fastest from ProcessBuilder in program run from IDE, slowest from terminal)
(从IDE运行程序中的ProcessBuilder最快,终端最慢)
To set the locale to C : 要将语言环境设置为C:
std::locale::global(std::locale(""));
See also http://msdn.microsoft.com/en-us/library/9dzxxx2c(v=vs.80).aspx 另请参见http://msdn.microsoft.com/en-us/library/9dzxxx2c(v=vs.80).aspx
HOME, TEMP HOME,TEMP
Might influence the location of temporary files 可能会影响临时文件的位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.