Qt程序的速度性能:Windows vs Linux [英] Speed performance of a Qt program: Windows vs Linux

查看:923
本文介绍了Qt程序的速度性能:Windows vs Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经张贴此问题这里,但由于它可能不是Qt特定的,我认为我可以尝试我的机会在这里。我希望这样做是不合适的(只是告诉我,如果是)。



我开发了一个小型科学程序,执行一些数学计算。我试图优化它,以便它尽可能快。现在我几乎完成了它为Windows,Mac和Linux用户部署。但我还无法在许多不同的计算机上测试它。



这里是我遇到的麻烦:要部署为Windows,我使用一台笔记本电脑,有两个Windows 7和Ubuntu 12.04安装在其上(双引导)。我比较了在这两个系统上运行的应用程序的速度,我很惊讶地发现,它至少是Windows的两倍慢!如果有小的差异,我不会感到惊讶,






  • 我让程序做的计算只是一些残酷和愚蠢的数学计算,基本上,它计算产物和余弦在一个循环,称为十亿次。另一方面,计算是多线程的:我启动像6 QThreads。

  • 笔记本电脑有两个核心@ 1.73Ghz。起初我以为Windows可能没有使用其中一个核心,但后来我看了处理器的活动,根据小图形,两个核心都运行100%。

  • 然后我认为Windows的C ++编译器没有使用Linux的C ++编译器自动执行的优化选项(像-O1 -O2),但显然它是这样。



我感到困扰的是,应用程序在Windows上慢得多(2到4次),它真的很奇怪。另一方面,我还没有尝试在其他计算机与Windows。



$ b

附加信息:一些数据...

b

虽然Windows似乎使用两个核心,我认为这可能与线程管理有关,这是为什么:



示例计算n °1(这个启动2个QThreads):




  • PC1-windows:7.33s

  • PC1 -linux:3.72s

  • PC2-linux:1.36s



示例计算n°2 (这将启动3个QThreads):




  • PC1-windows:6.84s

  • PC1-linux :3.24s

  • PC2-linux:1.06s



示例计算n°3一个启动6个QThreads):




  • PC1-windows:8.35s

  • PC1-linux:2.62





其中:




  • PC1-windows =我的2核笔记本电脑(@ 1.73Ghz)与Windows 7

  • PC1-linux = (@ 1.73Ghz)与Ubuntu 12.04

  • PC2-linux =我的8核笔记本电脑(@ 2.20Ghz)与Ubuntu 12.04



(当然,这并不令人震惊,PC2更快。对我来说这是令人难以置信的是PC1-windows和PC1-linux之间的区别。)



注意:我也试过在最近的电脑上运行程序核心@〜3Ghz,不记得确切)在Mac OS下,速度是相当于PC2-linux(或稍快)。



编辑:我会回答这里




  • 我刚刚在Windows上安装了Qt SDK,所以我想我有最新的版本的一切(包括MinGW?)。编译器是MinGW。 Qt版本是4.8.1。


  • 我没有使用优化标志,因为我注意到,当我在发布模式在我看来,如果我写的东西像QMAKE_CXXFLAGS + = -O1,这只有在调试生成的效果。


  • 生命线程等:这是很简单。当用户单击计算按钮时,同时启动2到6个线程(取决于他计算的内容),它们在计算结束时终止。没有太太花哨。每个线程只是做残酷的计算(除了一个,实际上,这使得一个(不是这样)小的计算每30ms,基本上检查错误是否足够小)。




编辑:最新发展和部分答案



这里有一些新的发展,所有这些:




  • 我想确定速度的差异是否与线程有关,程序,所以计算只使用1个线程,这样我们几乎比较了纯C ++代码的性能。事实证明,现在Windows只比Linux稍微慢一点(比如15%)。所以我想系统固有的一小部分(但不是不显着)的差异,但最大的部分是由于线程管理


  • p>正如有人(Luca Carlon,感谢)在评论中建议的,我试着用Microsoft Visual Studio(MSVC)的编译器构建应用程序,而不是MinGW。令人惊讶的是,计算(所有的线程和一切)现在只比Linux慢20%至50%!我想我会继续前进,并满足于此。我注意到,奇怪的是,纯C ++计算(只有一个线程)现在甚至更慢(比MinGW),这必须考虑到总体差异。因此,就我所知, MinGW比MSVC稍微好一点,除了它处理一个线程像一个moron




所以,我想有一些我可以做的,使MinGW(理想情况下,我宁愿使用它比MSVC)更好的处理线程,或者它只是不能。我会很惊讶,怎么不知道和记录?虽然我想我应该小心的得出结论太快,我只比较了一台电脑上的东西(暂时)。

解决方案

另一个选项可能是:在linux qt刚刚加载,这可能发生,即如果你使用KDE,而在Windows库中必须加载,因此这减慢计算时间。要检查多少库加载浪费你的应用程序,你可以用纯c ++代码编写一个虚拟测试。


I've already posted this question here, but since it's maybe not that Qt-specific, I thought I might try my chance here as well. I hope it's not inappropriate to do that (just tell me if it is).

I’ve developed a small scientific program that performs some mathematical computations. I’ve tried to optimize it so that it’s as fast as possible. Now I’m almost done deploying it for Windows, Mac and Linux users. But I have not been able to test it on many different computers yet.

Here’s what troubles me: To deploy for Windows, I’ve used a laptop which has both Windows 7 and Ubuntu 12.04 installed on it (dual boot). I compared the speed of the app running on these two systems, and I was shocked to observe that it’s at least twice as slow on Windows! I wouldn’t have been surprised if there were a small difference, but how can one account for such a difference?

Here are a few precisions:

  • The computation that I make the program do are just some brutal and stupid mathematical calculations, basically, it computes products and cosines in a loop that is called a billion times. On the other hand, the computation is multi-threaded: I launch something like 6 QThreads.
  • The laptop has two cores @1.73Ghz. At first I thought that Windows was probably not using one of the cores, but then I looked at the processor activity, according to the small graphic, both cores are running 100%.
  • Then I thought the C++ compiler for Windows didn’t the use the optimization options (things like -O1 -O2) that the C++ compiler for Linux automatically did (in release build), but apparently it does.

I’m bothered that the app is so mush slower (2 to 4 times) on Windows, and it’s really weird. On the other hand I haven’t tried on other computers with Windows yet. Still, do you have any idea why the difference?

Additional info: some data…

Even though Windows seems to be using the two cores, I’m thinking this might have something to do with threads management, here’s why:

Sample Computation n°1 (this one launches 2 QThreads):

  • PC1-windows: 7.33s
  • PC1-linux: 3.72s
  • PC2-linux: 1.36s

Sample Computation n°2 (this one launches 3 QThreads):

  • PC1-windows: 6.84s
  • PC1-linux: 3.24s
  • PC2-linux: 1.06s

Sample Computation n°3 (this one launches 6 QThreads):

  • PC1-windows: 8.35s
  • PC1-linux: 2.62s
  • PC2-linux: 0.47s

where:

  • PC1-windows = my 2 cores laptop (@1.73Ghz) with Windows 7
  • PC1-linux = my 2 cores laptop (@1.73Ghz) with Ubuntu 12.04
  • PC2-linux = my 8 cores laptop (@2.20Ghz) with Ubuntu 12.04

(Of course, it's not shocking that PC2 is faster. What's incredible to me is the difference between PC1-windows and PC1-linux).

Note: I've also tried running the program on a recent PC (4 or 8 cores @~3Ghz, don't remember exactly) under Mac OS, speed was comparable to PC2-linux (or slightly faster).

EDIT: I'll answer here a few questions I was asked in the comments.

  • I just installed Qt SDK on Windows, so I guess I have the latest version of everything (including MinGW?). The compiler is MinGW. Qt version is 4.8.1.

  • I use no optimization flags because I noticed that they are automatically used when I build in release mode (with Qt Creator). It seems to me that if I write something like QMAKE_CXXFLAGS += -O1, this only has an effect in debug build.

  • Lifetime of threads etc: this is pretty simple. When the user clicks the "Compute" button, 2 to 6 threads are launched simultaneously (depending on what he is computing), they are terminated when the computation ends. Nothing too fancy. Every thread just does brutal computations (except one, actually, which makes a (not so) small"computation every 30ms, basically checking whether the error is small enough).

EDIT: latest developments and partial answers

Here are some new developments that provide answers about all this:

  • I wanted to determine whether the difference in speed really had something to do with threads or not. So I modified the program so that the computation only uses 1 thread, that way we are pretty much comparing the performance on "pure C++ code". It turned out that now Windows was only slightly slower than Linux (something like 15%). So I guess that a small (but not unsignificant) part of the difference is intrinsic to the system, but the largest part is due to threads management.

  • As someone (Luca Carlon, thanks for that) suggested in the comments, I tried building the application with the compiler for Microsoft Visual Studio (MSVC), instead of MinGW. And suprise, the computation (with all the threads and everything) was now "only" 20% to 50% slower than Linux! I think I'm going to go ahead and be content with that. I noticed that weirdly though, the "pure C++" computation (with only one thread) was now even slower (than with MinGW), which must account for the overall difference. So as far as I can tell, MinGW is slightly better than MSVC except that it handles threads like a moron.

So, I’m thinking either there’s something I can do to make MinGW (ideally I’d rather use it than MSVC) handle threads better, or it just can’t. I would be amazed, how could it not be well known and documented ? Although I guess I should be careful about drawing conclusions too quickly, I’ve only compared things on one computer (for the moment).

解决方案

Another option it could be: on linux qt are just loaded, this could happens i.e. if you use KDE, while in Windows library must be loaded so this slow down computation time. To check how much library loading waste your application you could write a dummy test with pure c++ code.

这篇关于Qt程序的速度性能:Windows vs Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆