# $ pip3 install line_profiler memory_profiler
@profile
def main():
- l = list(range(10000))
- s = set(range(10000))
+ a = [*range(10000)]
+ b = {*range(10000)}
main()
$ python3 -m memory_profiler test.py
Line # Mem usage Increment Line Contents
=======================================================
1 37.668 MiB 37.668 MiB @profile
2 def main():
- 3 38.012 MiB 0.344 MiB l = list(range(10000))
- 4 38.477 MiB 0.465 MiB s = set(range(10000))
+ 3 38.012 MiB 0.344 MiB a = [*range(10000)]
+ 4 38.477 MiB 0.465 MiB b = {*range(10000)}
# $ pip3 install pycallgraph2
from pycallgraph2 import output, PyCallGraph
@@ -2274,7 +2274,7 @@ frames = []
y = sum(range(velocity))
frame = Image.new('L', (WIDTH, WIDTH))
draw = ImageDraw.Draw(frame)
- draw.ellipse(((WIDTH / 2) - R, y, (WIDTH / 2) + R, y + (R * 2)), fill='white')
+ draw.ellipse((WIDTH/2-R, y, WIDTH/2+R, y+R*2), fill='white')
frames.append(frame)
frames += reversed(frames[1:-1])
imageio.mimsave('test.gif', frames, duration=0.03)