《CPython Internals》閱讀筆記:p353-p355
《CPython Internals》學習第 18天,p353-p355 總結,總計 3 頁。
一、技術總結
1.benchmark(基準測試)
Python中常用的 benchmark 有 timeit, pyperformance。
(1)timeit
$ ./python -m timeit -c "x=1; x+=1; x**x"
1000000 loops, best of 5: 258 nsec per loop
我覺得這是一個很糟糕的示例,沒有看出這個示例有什么意義。對于timeit 模塊,我更希望放在整個項目中去看,看看它在實際項目中的應用。很遺憾,截止到目前,在我所看過的書中,關于 timeit 的使用都是測試一些代碼片段。
(2)關于timeit的一點說明
作者在第356也說“You might notice a minor (1-5%) improvement in performance.”——我覺得作者在這里的敘述有點本末倒置,timeit頂多算是驗證結果的一種手段,其實應該把重點放在“為什么性能提升了1-5%”。
2.profiler
Python 中常用的 profiler 有 cProfiler 或者 dtrace。
二、英語總結(生詞:2)
1.detrimental
(1)detriment: de-("away") + terere("to rub(摩擦), wear(to become weaker)")
u. harm or damage. Detriment refects the sense of sth being gradually worn away(使......磨損),leading to harm or less。
(2)detrimental
adj. causing harm or damage.
When making changes to CPython, you need to verify that your changes do not have a significant detrimental impact on performance(《CPython Internals》第353頁)。
2.median
(1)median
c. the value that is the middle one in a set of values arranged in order of size(中位數,中值)。示例:1.假設有一組數 1, 3, 3, 6, 7, 8, 9, 那么 median 是6。2.假設有一組數1, 2, 3, 4, 5, 6, 8, 9,那么 median 是(4+5)/2=4.5。
A benchmark will produce an average/median runtime of a fixed code snippet so that you can compare multiple versions of Python runtime(《CPython Internals》第353頁。)
關于英語的注解同步更新匯總到 https://github.com/codists/English-In-CS-Books 倉庫。
三、其它
今天沒有什么想說的。
四、參考資料
1. 編程
(1) Anthony Shaw,《CPython Internals》:https://book.douban.com/subject/35405785/
2. 英語
(1) Etymology Dictionary:https://www.etymonline.com
(2) Cambridge Dictionary:https://dictionary.cambridge.org

歡迎搜索及關注:編程人(a_codists)
浙公網安備 33010602011771號