Canvas performance test scripts.

This commit is contained in:
Juan Pablo Caram 2015-12-31 23:28:23 -05:00
parent 96885c80a4
commit 3b206493a3
3 changed files with 116 additions and 0 deletions

View File

@ -22,6 +22,21 @@ log = logging.getLogger('base')
class CanvasCache(QtCore.QObject):
"""
Case story #1:
1) No objects in the project.
2) Object is created (new_object() emits object_created(obj)).
on_object_created() adds (i) object to collection and emits
(ii) new_object_available() then calls (iii) object.plot()
3) object.plot() creates axes if necessary on
app.collection.figure. Then plots on it.
4) Plots on a cache-size canvas (in background).
5) Plot completes. Bitmap is generated.
6) Visible canvas is painted.
"""
# Signals:
# A bitmap is ready to be displayed.

View File

@ -0,0 +1,95 @@
from __future__ import division
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import cStringIO
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
import cProfile
import sys
def gen_data():
N = 100000
x = np.random.rand(N) * 10
y = np.random.rand(N) * 10
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radiuses
data = x, y, area, colors
return data
# @profile
def large_plot(data):
x, y, area, colors = data
fig = Figure(figsize=(10, 10), dpi=80)
axes = fig.add_axes([0.0, 0.0, 1.0, 1.0], alpha=1.0)
axes.set_frame_on(False)
axes.set_xticks([])
axes.set_yticks([])
# axes.set_xlim(0, 10)
# axes.set_ylim(0, 10)
axes.scatter(x, y, s=area, c=colors, alpha=0.5)
axes.set_xlim(0, 10)
axes.set_ylim(0, 10)
canvas = FigureCanvasAgg(fig)
canvas.draw()
# canvas = FigureCanvasQTAgg(fig)
# buf = canvas.tostring_rgb()
buf = fig.canvas.tostring_rgb()
ncols, nrows = fig.canvas.get_width_height()
img = np.fromstring(buf, dtype=np.uint8).reshape(nrows, ncols, 3)
return img
def small_plot(data):
x, y, area, colors = data
fig = Figure(figsize=(3, 3), dpi=80)
axes = fig.add_axes([0.0, 0.0, 1.0, 1.0], alpha=1.0)
axes.set_frame_on(False)
axes.set_xticks([])
axes.set_yticks([])
# axes.set_xlim(5, 6)
# axes.set_ylim(5, 6)
axes.scatter(x, y, s=area, c=colors, alpha=0.5)
axes.set_xlim(4, 7)
axes.set_ylim(4, 7)
canvas = FigureCanvasAgg(fig)
canvas.draw()
# canvas = FigureCanvasQTAgg(fig)
# buf = canvas.tostring_rgb()
buf = fig.canvas.tostring_rgb()
ncols, nrows = fig.canvas.get_width_height()
img = np.fromstring(buf, dtype=np.uint8).reshape(nrows, ncols, 3)
return img
def doit():
d = gen_data()
img = large_plot(d)
return img
if __name__ == "__main__":
d = gen_data()
if sys.argv[1] == 'large':
cProfile.runctx('large_plot(d)', None, locals())
else:
cProfile.runctx('small_plot(d)', None, locals())

6
tests/canvas/prof.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
echo "*** LARGE ***"
python performance.py large | egrep "(\(scatter\))|(\(draw\))|(tostring_rgb)|(fromstring)"
echo "*** SMALL ***"
python performance.py small | egrep "(\(scatter\))|(\(draw\))|(tostring_rgb)|(fromstring)"