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

高效能PYTHON程式設計

by Micha Gorelick, Ian Ozsvald
August 2015
Intermediate to advanced
384 pages
7h 42m
Chinese
GoTop Information, Inc.
Content preview from 高效能PYTHON程式設計
透過效能分析找出瓶頸
|
37
叫其他函式上(唯一比較重要的是
abs
)。可以看到,只有一點點時間花在準備工作上,
大多數執行時間都耗費在計算上。
使用
runsnake
時,你可以點擊函式,並且深入複雜的嵌套呼叫(nested call)。當團隊在
討論某段程式碼執行緩慢的原因時,這項工具是非常寶貴的。
2-5 RunSnakeRun 視覺化 cProfile 的效能分析檔案
使用 line_profiler 進行一行一行的量測
Ian 的觀點來看,Robert Kern
line_profiler
是辨識 Python 程式碼裡頭計算密集型
問題之成因的最強大工具,它在一行一行的基礎上,針對個別的函式進行效能分析,因
此,你應該從
cProfile
開始,透過高階觀點,判斷出要使用
line_profiler
深入分析哪
些函式。
在修改程式碼時,值得花時間列印及註釋這項工具的輸出版本,所以你會有能夠迅速參
照的變更紀錄(成功或不成功)。在進行一行一行的程式碼變更時,不要單單倚賴你的
記憶力。
38
|
第二章
要安裝
line_profiler
,就執行
pip
install
line_profiler
命令。
裝飾器(
@profile
)被用來標記選取的函式,
kernprof.py
指令稿被用來執行你的程式
碼,而且,CPU ...
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Kafka权威指南

Kafka权威指南

Neha Narkhede, Gwen Shapira, Todd Palino
手把手教会你linux

手把手教会你linux

桑德.范.乌格特
流畅的Python

流畅的Python

Luciano Ramalho
精通機器學習

精通機器學習

Aurélien Géron

Publisher Resources

ISBN: 9789863477105