Qt和MFC的效率對比

Qt和MFC的效率對比

之前一直做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也會很累。

 

至於其他 框架,沒有什麼可比性,他們是託管代碼。

 

歡迎訪問我的文章,這裏是編程pdf電子書供參考。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章