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程式設計
透過效能分析找出瓶頸
|
29
我們的結果顯示,呼叫
calc_pure_python
的總成本為 13.1 秒(最好的情況),而先前以
@timefn
裝飾器量測到單一的
calculate_z_serial_purepython
呼叫花費 12.2 秒,主要的
差異是建立
zs
cs
串列所花費的時間。
IPython 裡,我們能夠以相同的方式使用神奇的
%timeit
。假如你正在 IPython 裡以互
動的方式開發你的程式碼,而函式位在區域的名稱空間中(可能因為你在使用
%run
),
那麼,你就可以使用︰
%timeit calc_pure_python(desired_width=1000, max_iterations=300)
值得考量一般電腦上的負載變異,許多在背景執行的任務(例如,Dropboxbackups
都會隨機地影響 CPU 與磁碟資源。網頁裡的指令稿也會引起無可預測的資源耗用。圖
2-4 顯示單一 CPU 因為我們所執行的某些計時步驟而達到 100% 的使用率;而此機器上
的其他核心則各自輕鬆地處理其他任務。
2-4 Ubuntu 上的 System Monitor 顯示在計時我們的函式時的 CPU 使用率變化
偶爾,System Monitor 顯示出機器上的活動尖峰,最好觀察你的 System Monitor,確認
沒有其他東西在干擾你的重要資源(CPU,磁碟,網路)。
使用 Unix time 指令做簡單的計時
我們可以暫時離開 Python,使用類 Unix 系統上的標準系統工具。下面內容將針對程式 ...
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