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程式設計
透過效能分析找出瓶頸
|
31
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
這裡最有用的指標或許是
Major
(requiring
I/O)
page
faults
,因為這表示作業系統是否
需要從磁碟載入資料頁(因為資料不在 RAM 裡),這會造成速度懲罰。
在我們的範例裡,程式碼與資料需求很小,所以沒有分頁錯誤(page fault)發生。如果
你擁有記憶體密集(memory-bound)的行程,或者一些使用可變且大量 RAM 的程式,
你可能會發現,這提供線索,告訴你哪個程式正因為作業系統層級的磁碟存取而被拖
慢,因為它的某些部分在 RAM 與磁碟之間被交換。
使用 cProfile 模組
cProfile
是標準程式庫裡的內建效能分析工具,它掛鉤到 CPython 裡的虛擬機器,量測
執行它所看見的每個函式所需花費的時間。這衍生出比較大的額外成本,但是你也得到
相對多的資訊,有時候,這些額外的資訊能夠讓你對程式碼產生出乎意料的深入洞察。
cProfile
是標準程式庫裡的三個效能測試器(profiler)之一;其他兩個是
hotshot
profile
hotshot
是實驗性的程式碼,而
profile
是原始的純 Python 效能測試器。
cProfile
具有與
profile
相同的介面,充分被支援,並且是預設的效能測試工具 ...
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