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程式設計
26
|
第二章
2-3 Julia set 的純灰階圖
簡單的計時方法— print 與裝飾器
在範例 2-4 之後,我們看到程式碼的幾個
print
陳述式產生的輸出。在 Ian 的筆電上,
使用 CPython 2.7 時,這段程式碼大約耗費 12 秒鐘。注意,執行時間總是會有一些變
異,在計時你的程式碼時,必須觀察執行時間的正常變異,否則,你可能會誤將程式碼
的改進歸因於執行時間的隨機變動。
在執行你的程式碼時,你的電腦還會執行其他任務,例如,存取網路、磁碟或 RAM
而這些因素都會對你的程式的執行時間造成變異。
Ian 的筆電是 Dell E6420,具有 Intel Core I7-2720QM CPU2.20 GHz6 MB 快取,四
核心)和 8 GB RAM,執行 Ubuntu 13.10
calc_pure_python
(範例 2-2)裡,我們可以看到幾個
print
陳述式,這是
在函式裡
量測一段程式碼的執行時間的最簡單方式。這是非常基本的方法,然而,儘管迅速又隨
性,當你剛看到一段程式碼時,那會是非常有用的。
透過效能分析找出瓶頸
|
27
在偵錯程式碼及進行效能分析時,使用
print
陳述式是很平常的,但很快就會變得不好
管理,然而,對簡單的調查來說還是很有用的。當你使用完畢 ...
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