Skip to Main Content
高效能PYTHON程式設計
book

高效能PYTHON程式設計

by Micha Gorelick, Ian Ozsvald
August 2015
Intermediate to advanced content levelIntermediate to advanced
384 pages
7h 42m
Chinese
GoTop Information, Inc.
Content preview from 高效能PYTHON程式設計
透過效能分析找出瓶頸
|
43
57 1 58.0 0.0 print calculate_z_serial_purepython
.func_name + " took", secs, "seconds"
58
# this sum is expected for 1000^2 grid...
59 1 9799.0 0.0 assert sum(output) == 33219980
memory_profiler 診斷記憶體使用情況
就像 Robert Kern
line_profiler
套件量測 CPU 的使用情況一樣,Fabian Pedregosa
Philippe Gervais
memory_profiler
模組在一行一行的基礎上量測記憶體的使用狀況。
瞭解你的程式碼的記憶體使用特性允許你問自己二個問題︰
我們能夠重寫函式,使用
較少
RAM,更有效地運作嗎?
我們可以使用
更多
RAM,透過快取節省 CPU 循環嗎?
memory_profiler
的運作方式非常類似
line_profiler
,但跑起來慢很多,假如你有安
psutil
套件(選用的,但強烈推薦),
memory_profiler
會執行得比較迅速。記憶體
分析很容易就會將你的程式碼拖慢 10 100 倍。實務上,你可能偶爾才使用
memory_
profiler
,但比較常使用
line_profiler
(做 CPU 效能分析)。
使用
pip
install
memory_profiler
命令安裝 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

流畅的Python

流畅的Python

Luciano Ramalho
手把手教会你linux

手把手教会你linux

桑德.范.乌格特

Publisher Resources

ISBN: 9789863477105