Verimli Python Kodu Yazmak
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 kullanımı%load_ext memory_profiler
%mprun -f convert_units convert_units(heroes, hts, wts)
memory_profiler kullanırken fonksiyonlar içe aktarılmalıdırhero_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)

Bu örnekteki veri, 35.000 kahramandan rastgele bir örnektir.
(orijinal 480 süper kahraman veri kümesi değil)
%mprun -f convert_units convert_units(heroes, hts, wts)

Küçük bellek tahsisleri 0.0 MiB çıktısına yol açabilir.
(orijinal 480 süper kahraman veri kümesi kullanılarak)
%mprun -f convert_units convert_units(heroes, hts, wts)

Verimli Python Kodu Yazmak