High Performance Python (2nd Edition) cover

High Performance Python (2nd Edition)

No rating yet
Word count
280K words
Chapters
9
Series
Turing Programming Series
ISBN
9787115488770

Tags

Summary

This book is aimed at developers who already know the basics of Python and want to make their programs run faster. Its guiding principle is "measure first, optimize second": first use test and benchmark scripts, cProfile, line_profiler, memory_profiler, and other tools to locate bottlenecks in the program and in memory, then work from pure-Python choices of data structures and algorithms, caching and memoization, and comprehensions and generators, to NumPy and Pandas array-style coding with numexpr, to using Cython for near-C execution speed, and to just-in-time compilation approaches such as Numba and PyPy. The second half discusses ways to implement concurrency and parallelism, including asynchronous programming, multiprocessing, and OpenMP, then distributed computing tools such as Dask, PySpark, and mpi4py, and finally engineering practices for high-performance programs: design thinking, source organization, virtual environments and containerization, and continuous integration. A particle simulator runs through several chapters, comparing the same code at different levels of optimization so readers can understand the applicable boundaries and costs of each technique.

Editor's review

不少 Python 性能书容易写成“技巧清单”,这本篇幅不大却难得地讲清了顺序:先确认瓶颈在哪里,再决定花多少成本去换速度。作者用粒子模拟器这一个例子从头改到尾,读者能直观看到同一份逻辑在纯 Python、NumPy、Cython、Numba、多进程下的差别,也就明白为什么“提前优化”往往是浪费。剖析工具部分给得比较实在,cProfile、line_profiler、memory_profiler 都有可上手的操作路径;分布式一章把 Dask、PySpark、mpi4py 放在一起对比,适合做技术选型时翻一翻。全书只有一百八十多页,通勤路上读一两章压力不大,适合当成性能工具箱来查阅。

Who it's for

A good fit for

  • 已经能写 Python 脚本,但遇到大数据量或计算密集型任务就卡住的中级开发者
  • 从事数据分析、科学计算,需要 NumPy、Pandas、Cython 加速手段的工程师
  • 想系统了解剖析工具与性能测试方法的技术人员
  • 准备做技术选型,需要快速比较 Numba、PyPy、Dask 等方案的人

Not a good fit for

  • 完全没有 Python 基础的初学者,书中默认读者熟悉语法与常用库
  • 只想找现成代码片段、不愿动手跑基准测试的读者
  • 期待深入讲解 CPython 解释器内部实现的读者,本书偏工程实用

Reading tips

  1. 先读第1章和第9章,建立“先测量后优化”的流程观,再按需翻中间章节
  2. 把你自己的慢代码替换书中的粒子模拟器做练习,对照不同方案的耗时变化
  3. 读 Cython、Numba、PyPy 部分时务必在本地环境实际编译运行,否则很难体会差异
  4. 分布式一章可按现有技术栈挑 Dask 或 PySpark 其中一条路线深入,不必全读

About the publisher

Posts & Telecom Press China · Founded in 1953

Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.

Contents

  1. Chapter 1 Benchmarking and Profiling
  2. Chapter 2 Pure Python Optimization
  3. Chapter 3 Fast Array Operations with NumPy and Pandas
  4. Chapter 4 C Performance with Cython
  5. Chapter 5 Exploring Compilers
  6. Chapter 6 Implementing Concurrency
  7. Chapter 7 Parallel Processing
  8. Chapter 8 Distributed Processing
  9. Chapter 9 High-Performance Design

FAQ

这本书和《Python高性能编程》是同一本吗?
不是。本书作者为加布丽埃勒·拉纳诺,原书为 Python High Performance 第2版,2018年由人民邮电出版社出版;《Python高性能编程》作者是米夏·戈雷利克与伊恩·欧日沃尔德,两者内容与章节安排都不同。
需要什么基础才能读?
需要能熟练编写 Python 代码,了解函数、类、列表与字典等基本用法,最好用过 NumPy 或 Pandas。书中不讲解语法入门,而是直接进入性能分析与优化手段。
书里的例子用的是 Python 2 还是 3?
本版主要基于 Python 3 编写,涉及的 Cython、Numba、asyncio 等工具均以 Python 3 生态为主,读者按 Python 3 环境跟随练习即可。
篇幅不大,内容会不会太浅?
本书定位是性能工具箱与入门路径,每个主题讲清“何时用、怎么用、代价是什么”,不追求穷尽细节。深度优化还需结合官方文档与项目实践。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category