Well, this is another Python vs Ruby article, hope it is useful.
Today I have measured memory consumption of QtRuby against PyQt4. quite similar scripts were used in both tests and the results are here:
Python 3.3 - 11,040K / 19,456K shared memory
Python 2.7.3 - 10,056K / 19,008K shared memory
Ruby 1.9.3p327 - 9,380K / 21,660K shared memory
The memory consumption is very similar too. Writing the code in QtRuby is more pleasant though.
and here are the sources:
Python:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = QWidget()
widget.setWindowTitle("Hello QtPython xxxx")
widget.resize(200,100)
button = QPushButton("Quit")
button.clicked.connect(QApplication.quit)
label = QLabel("Hello Qt in the Python way!")
layout = QVBoxLayout()
layout.addWidget(button, 0, Qt.AlignCenter)
layout.addWidget(label, 0, Qt.AlignCenter)
widget.setLayout(layout)
widget.show()
sys.exit(app.exec_())
Ruby:
require 'Qt4'
Qt::Application.new(ARGV) do
Qt::Widget.new do
self.window_title = 'Hello QtRuby v1.0'
resize(200, 100)
button = Qt::PushButton.new('Quit') do
connect(SIGNAL :clicked) { Qt::Application.instance.quit }
end
label = Qt::Label.new('<big>Hello Qt in the Ruby way!</big>')
self.layout = Qt::VBoxLayout.new do
add_widget(label, 0, Qt::AlignCenter)
add_widget(button, 0, Qt::AlignRight)
end
show
end
exec
end
0 comments:
Post a Comment