之前一直做mfc,昨天看了一晚上的Qt,瞬间就喜欢上它了,Qt在windows下应该没有mfc的运行效率高,但是我想知道差多少,不知有没有大牛做过这方面的对比。Qt和MFC,WinForm,WPF这几个对比,在哪个位置?
回答:
Qt 是 C++ 的一个框架,要说慢的话,可能信号槽的触发会慢点。但是几乎可以忽略不计。
Qt 的官方文档有大约这么一段话
Compared to callbacks, signals and slots are slightly slower because of the increased flexibility they provide, although the difference for real applications is insignificant. In general, emitting a signal that is connected to some slots, is approximately ten times slower than calling the receivers directly, with non-virtual function calls. This is the overhead required to locate the connection object, to safely iterate over all connections (i.e. checking that subsequent receivers have not been destroyed during the emission), and to marshall any parameters in a generic fashion. While ten non-virtual function calls may sound like a lot, it's much less overhead than any new or delete operation, for example. As soon as you perform a string, vector or list operation that behind the scene requires new or delete, the signals and slots overhead is only responsible for a very small proportion of the complete function call costs.
The same is true whenever you do a system call in a slot; or indirectly call more than ten functions. On an i586-500, you can emit around 2,000,000 signals per second connected to one receiver, or around 1,200,000 per second connected to two receivers. The simplicity and flexibility of the signals and slots mechanism is well worth the overhead, which your users won't even notice.
就是说,信号槽机制比回调机制慢10倍。主要损失在类型检查和参数安全上。
想想也是,人们会关心点击一个按钮后,多长时间完成任务。而很少会关心点击一个按钮后,多快的开始任务。
至于,信号槽机制的性能,大约可以每秒处理2百万个信号。
也就是说,你有 2000个 定时器,每个定时器 每秒触发 1000次。就达到了信号槽机制的瓶颈。我想如果这样的话,MFC也会很累。
至于其他 框架,没有什么可比性,他们是托管代码。