Is there a better place to post this question?  Sorry if this isn't the
right venue.

Am I doing something wrong -- is there a way to make the following pygame
program run faster?
It runs in 10.5 seconds, whereas an equivalent program invoking SDL2 from
Julia runs in 3.0 seconds (I'm happy to post the Julia code as well.)
(I'm using pygame 1.9.4 via Anaconda in Windows 10 on a Lenovo Thinkpad
T470p.)
Could it be simply because Julia is compiled and Python is interpreted, or
perhaps that SDL2 is faster than SDL1?

import pygame
import timeit

widthcell=5 # pixels
ncellswide=100
size = ncellswide*widthcell

pygame.init()
display = pygame.display.set_mode((size,size),
pygame.HWSURFACE|pygame.DOUBLEBUF)

def run():
    color1=(105,105,0); color2=(0,0,150)
    for i in range(500):
        for row in range(ncellswide):
            for col in range(ncellswide):
                pygame.draw.rect(display, color1, [row*widthcell,
col*widthcell, widthcell-1, widthcell-1])
        pygame.display.update()
        color1,color2=color2,color1

total_time = timeit.timeit('run()', 'from __main__ import run', number=1)
print(total_time," seconds")
pygame.quit()

Reply via email to