Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
The performance effect of text overflow in a QPlainTextEdit with setMaximumBlockCount set.
from pyface.qt import QtGui, QtCore
import time
import pandas
import numpy
from matplotlib import pyplot as plt
a = QtGui.QApplication.instance() or QtGui.QApplication([])
w = QtGui.QPlainTextEdit()
w.setMinimumSize(600, 400)
#w.setReadOnly(True)
w.show()
append_sizes = [100, 200, 500, 1000, 2000, 5000, 10000, 20000]
buffer_sizes = [100, 200, 500, 1000, 2000, 5000, 10000, 20000]
def setup(count):
w.setPlainText('')
# Comment next line to start from empty widget
w.setPlainText('\n'.join(map(str, xrange(count))))
w.setMaximumBlockCount(count)
w.show()
def time_append(buffer_size, text_size):
setup(buffer_size)
text = '\n'.join(map(str, xrange(text_size)))
t = time.time()
# Uncomment next line to see effect of text overflow
# w.setPlainText('')
w.appendPlainText(text)
t = time.time()-t
print 'count: %s: text: %s time: %s' %(buffer_size, text_size, t)
return t
def do_one(buffer_index, text_index):
print buffer_index, text_index
buffer_size = buffer_sizes[buffer_index]
append_size = append_sizes[text_index]
df[buffer_size][append_size] = time_append(buffer_size, append_size)
text_index += 1
if text_index == len(append_sizes):
text_index = 0
buffer_index += 1
if buffer_index == len(buffer_sizes):
do_plot()
return
QtCore.QTimer.singleShot(100, lambda:do_one(buffer_index, text_index))
def do_plot():
print df
for col in df:
plt.loglog(df[col].index, df[col].values, '.-', label=str(df[col].name))
plt.xlabel('Buffer Size')
plt.ylabel('Time to Append')
plt.legend(loc='best')
plt.show()
def do_it():
print 0,0
do_one(0, 0)
df = pandas.DataFrame(numpy.zeros((len(buffer_sizes), len(append_sizes))),
index=append_sizes, columns=buffer_sizes)
QtCore.QTimer.singleShot(100, do_it)
a.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment