You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apologies if this is the wrong place (feel free to close if so) but I thought I'd gather some cheap wins on the performance-side of pyscroll.
- Convert list() to [] (more below)
I haven't looked everywhere but orthographic.py has a load of these which are low hanging fruit
- Convert fors to comprehensions (more below)
Again, I haven't looked elsewhere but orthographic.py has a few instance that we could speed up
- Convert dict() to {}
Same deal as the lists. {} is faster. There's only two occurrences of dict() in the repo so this isn't really worth doing but worth keeping in mind for future
- Experiment with fblits
This would be a breaking change as it's pygame-ce only but apparently has some performance gains. I tried a quickl replace of blits -> fblits and sadly saw no improvements on my end but maybe with some reworking we could get some good gains. Ref: https://pyga.me/docs/ref/surface.html#pygame.Surface.fblits
Convert list() to []
[] is faster than list()
A million runs with each gives the following
[] took 0.06097865104675293
list() took 0.10919380187988281
The script is
import time
limit = 1000000
start = time.time()
for i in range(limit):
a = []
end = time.time()
duration = end - start
print('[] took ', duration)
start = time.time()
for i in range(limit):
a = list()
end = time.time()
duration = end - start
print('list() took ', duration)
Convert fors to list comprehensions
Same story. List comprehensions run significantly quicker than fors and there's a few places where we can optimise.
A thousand runs of populating 10000 numbers gave me
comprehension took 0.2832183837890625
for took 0.6464605331420898
The script is
import time
limit = 1000
start = time.time()
for i in range(limit):
a = [x +1 for x in range(10000)]
end = time.time()
duration = end - start
print('comprehension took ', duration)
start = time.time()
for i in range(limit):
a = []
app = a.append
for x in range(10000):
app(x+1)
end = time.time()
duration = end - start
print('for took ', duration)
If there's a reason these are left as they are then I'm happy to leave it but otherwise I might start tackling these soon.
Thanks and feel free to add to my list!
The text was updated successfully, but these errors were encountered:
Apologies if this is the wrong place (feel free to close if so) but I thought I'd gather some cheap wins on the performance-side of pyscroll.
list()
to[]
(more below)orthographic.py
has a load of these which are low hanging fruitfor
s to comprehensions (more below)orthographic.py
has a few instance that we could speed updict()
to{}
{}
is faster. There's only two occurrences ofdict()
in the repo so this isn't really worth doing but worth keeping in mind for futurefblits
blits
->fblits
and sadly saw no improvements on my end but maybe with some reworking we could get some good gains. Ref: https://pyga.me/docs/ref/surface.html#pygame.Surface.fblitsConvert
list()
to[]
[]
is faster thanlist()
A million runs with each gives the following
The script is
Convert
for
s to list comprehensionsSame story. List comprehensions run significantly quicker than
for
s and there's a few places where we can optimise.A thousand runs of populating 10000 numbers gave me
The script is
If there's a reason these are left as they are then I'm happy to leave it but otherwise I might start tackling these soon.
Thanks and feel free to add to my list!
The text was updated successfully, but these errors were encountered: