Wydajny kod w Pythonie
Logan Thomas
Scientific Software Technical Trainer, Enthought
import sys
nums_list = [*range(1000)]
sys.getsizeof(nums_list)
9112
import numpy as np
nums_np = np.array(range(1000))
sys.getsizeof(nums_np)
8096
memory_profilerpip install memory_profiler
memory_profiler%load_ext memory_profiler
%mprun -f convert_units convert_units(heroes, hts, wts)
memory_profilerhero_funcs.py
from hero_funcs import convert_units
%load_ext memory_profiler
%mprun -f convert_units convert_units(heroes, hts, wts)
%mprun -f convert_units convert_units(heroes, hts, wts)

%mprun -f convert_units convert_units(heroes, hts, wts)

%mprun -f convert_units convert_units(heroes, hts, wts)

%mprun -f convert_units convert_units(heroes, hts, wts)

%mprun -f convert_units convert_units(heroes, hts, wts)

%mprun -f convert_units convert_units(heroes, hts, wts)

%mprun -f convert_units convert_units(heroes, hts, wts)

Dane użyte w tym przykładzie to losowa próbka 35 000 bohaterów.
(nie oryginalny zbiór 480 superbohaterów)
%mprun -f convert_units convert_units(heroes, hts, wts)

Małe alokacje pamięci mogą dawać wynik 0.0 MiB.
(oryginalny zbiór 480 superbohaterów)
%mprun -f convert_units convert_units(heroes, hts, wts)

Wydajny kod w Pythonie