Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
screenspeedtest.py
import ui, io, Image, matplotlib.image,numpy, timeit
print(__file__)
A=numpy.random.rand(300,300,3)
Au=(255*A).astype('uint8')
B=io.BytesIO()
def p(format='jpeg'):
B.seek(0)
Image.fromarray(Au).save(B,format=format)
return ui.Image.from_data(B.getvalue())
def m(format='jpeg'):
B.seek(0)
matplotlib.image.imsave(B,A,format=format)
return ui.Image.from_data(B.getvalue())
N=30
print('matplotlib jpeg')
print(N/timeit.timeit('m("jpeg")',number=N, globals=globals()), 'fps')
print('pil jpeg')
print(N/timeit.timeit('p("jpeg")',number=N, globals=globals()), 'fps')
print('matplotlib png')
print(N/timeit.timeit('m("png")',number=N, globals=globals()), 'fps')
print('pil png')
print(N/timeit.timeit('p("png")',number=N, globals=globals()), 'fps')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.