Skip to content

Instantly share code, notes, and snippets.

@jsbain
Created October 23, 2018 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbain/1df982ee81e78ae8958b073fa7194a9c to your computer and use it in GitHub Desktop.
Save jsbain/1df982ee81e78ae8958b073fa7194a9c to your computer and use it in GitHub Desktop.
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