Skip to content

Performance using load_pixels #238

Answered by hx2A
phitaylr asked this question in Q&A
Feb 18, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

py5 performance has been close enough to Processing's Java mode that I've never noticed any problems.

That makes me very happy to hear!

Any suggestions for improving performance?

To answer your question, first I'd have to explain a bit about how py5 works.

First, Python and Java don't share the same memory space, and second, there's a small performance penalty when a py5 method makes a call to java. Think of it as a toll you pay when going from Python to Java. The toll is small but it will accumulate if you do this in a loop, especially a loop for every pixel in the sketch.

This code here:

    for i in range(py5.width*py5.height):
        py5.pixels[i] = c

is going to be slow because p…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@phitaylr
Comment options

@hx2A
Comment options

Answer selected by phitaylr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants