Performance Issue - Pygame Support For Codon #375
Replies: 3 comments 3 replies
-
@cool-dev-guy Type conversion and function calls between Codon and CPython incurs a performance cost, which should be taken into account when designing and implementing code. Since CPython has its own runtime environment, data must flow back and forth between CPython and Codon. By avoiding the lookup of the "circle" function in each iteration, you can optimize it in both CPython and Codon. import time
from python import pygame # Codon
# import pygame # CPython
pygame.init()
# Create a surface with size 640x480 pixels
surface = pygame.Surface((640, 480))
# time to draw circle using pygame.draw.circle
t = time.time()
for i in range(1000000):
pygame.draw.circle(surface, (255, 0, 0), (i, i), 10)
print(time.time() - t)
# Codon: 1.95779 secs
# CPython: 0.70422 secs
# time to look up circle function
t = time.time()
for i in range(1000000):
circle = pygame.draw.circle
print(time.time() - t)
# Codon: 0.477455 secs
# CPython: 0.14289 secs
# time to draw circle using circle
t = time.time()
circle = pygame.draw.circle
for i in range(1000000):
circle(surface, (255, 0, 0), (i, i), 10)
print(time.time() - t)
# Codon: 1.1882 secs
# CPython: 0.62985 secs |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
(Q1) is there any way to import cpp headers to codon (eg:SDL.h)? Or any other methods? (Q2) does python's .so (made from setuptools) be directly imported to codon?(like : import pythonlib as pl) |
Beta Was this translation helpful? Give feedback.
-
I was working on using pygame with codon.
And i was successful in it,But :
And it took:
Here codon takes
more time
,is there a way i can do it in small time?Run:
codon build -exe -release main.py
Beta Was this translation helpful? Give feedback.
All reactions