A simple benchmark of different ways to draw shapes to canvas #3680
viblo
started this conversation in
Show and tell
Replies: 2 comments
-
Small addition, today I made the same thing using pygame (running native, not through pyodide/wasm), and its about half the speed of pure js. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for sharing the benchmark! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I wanted to draw some shapes to canvas for a project Im working on. Instead of guessing the performance I made a simple benchmark of different methods. I couldnt find any similar info already, post here to help others, and also get input if I missed something.
In short, I could think of 3 (4) different methods to draw shapes to canvas:
Each method fills the canvas with a rect, draws one circle and finally draws one line. This is then repeated 250 / 500 times and finally I run the test 100 times and take the smallest time. For fun I tested the drawing methods from the 3 browsers I had available, FF & Edge on my laptop, and Chrome on my phone.
Numbers
(time to render a frame in ms)
I was surprised that my (new) mobile could keep up with the laptop. Also it seems like the first idea, draw fully on the Python side to a Pillow image is not at all a bad idea, it also has the upside that the code can be reused for non-web/pyodide usage which is nice!
I put it all on jsfiddle, you can try yourself here:
https://jsfiddle.net/nyqvp0w7/
Beta Was this translation helpful? Give feedback.
All reactions