# 蒂姆·彼得斯（软件工程师）

**蒂姆·彼得斯**（Tim Peters）是一位软件工程师，也是 [Python](https://www.edgepedia.org/zh/python-programming-language) 的长期核心开发者。他是 Timsort 排序算法的作者——该算法由他于 2002 年设计，后来成为 Python 的标准列表排序；他也是《Python 之禅》的作者，那是 19 行设计箴言<sup>[1](https://github.com/python/cpython/blob/main/Objects/listsort.txt)</sup><sup> • </sup><sup>[2](https://mail.python.org/pipermail/python-dev/2002-July/026897.html)</sup><sup> • </sup><sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup>。Python 软件基金会向他颁发了 2017 年度杰出服务奖；Python 的创造者[吉多·范罗苏姆](https://www.edgepedia.org/zh/guido-van-rossum)（Guido van Rossum）称他为导师，说他最大的贡献是多年间在 Python 邮件列表上回答问题、引导讨论<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup>。

| 关键事实 | 详情 |
|---|---|
| 代表作 | Timsort，一种自适应、稳定、自然的归并排序，2002 年 7 月在 python-dev 上公布，至今仍是 Python 的标准列表排序<sup>[1](https://github.com/python/cpython/blob/main/Objects/listsort.txt)</sup><sup> • </sup><sup>[2](https://mail.python.org/pipermail/python-dev/2002-July/026897.html)</sup> |
| 更广泛的采用 | Java 标准库、OpenJDK、Android 运行时和 V8 JavaScript 引擎中的标准排序<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup><sup> • </sup><sup>[4](https://pyvideo.org/pycon-us-2023/quicksort-timsort-powersort-algorithmic-ideas-engineering-tricks-and-trivia-behind-cpythons-new-sorting-algorithm.html)</sup> |
| 《Python 之禅》 | 1999 年写下的 19 行诗，提炼了范罗苏姆的设计品味，在 PEP 讨论中被引用，可通过 `import this` 查看<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup><sup> • </sup><sup>[5](https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim)</sup> |
| 最坏情况界 | 采用十余年后才首次被证明为 O(n log n)；运行时间为 1.5nH + O(n)，其中 H 是游程分布的熵<sup>[6](https://arxiv.org/html/1805.08612v3)</sup> |
| 社区角色 | 2017 年 PSF 杰出服务奖；2001—2014 年任 PSF 理事；发明“代言吉多”，以免范罗苏姆被邮件淹没<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup><sup> • </sup><sup>[5](https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim)</sup> |
| 早期职业生涯 | 加入 Python 项目之前，在克雷研究公司（Cray Research）写编译器，在巨龙系统公司（Dragon Systems）开发语音转文字软件<sup>[5](https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim)</sup> |
| 后期活动 | 在 `:=` 之争和范罗苏姆 2018 年辞去 BDFL 之后，在 Python 邮件列表上不如从前活跃<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup> |

## 生平与在 Python 社区中的角色

彼得斯曾供职于[克雷研究公司](https://www.edgepedia.org/zh/cray-research)，为超级计算机编写编译器；也曾在巨龙系统公司编写语音转文字软件——当时这项工作被普遍认为基本不可能完成。此后，他在 Python 的极早期就开始使用这门语言，从发布前的 Python 0.9.1 起步，成为继范罗苏姆之后这门语言事实上的第二位用户<sup>[5](https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim)</sup>。

2000 年末，五位 Python 人——吉多·范罗苏姆、弗雷德·德雷克（Fred Drake）、杰里米·希尔顿（Jeremy Hylton）、蒂姆·彼得斯和巴里·华沙（Barry Warsaw）——离开 BeOpen，受雇于数字创作公司（Digital Creations）<sup>[7](https://lwn.net/2000/1102/a/pythondev.php3)</sup>。彼得斯于 2001 年至 2014 年担任 Python 软件基金会理事<sup>[5](https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim)</sup>。

**代言吉多。** 在设计争论中，彼得斯发明了“代言吉多”这一说法：把范罗苏姆大概会作出的决定表述出来，好让这位创造者从汹涌的邮件中脱身。范罗苏姆称他为导师，并说在极早期 Python 的设计演进中，两人大体上是伙伴关系，彼得斯充当重要特性的把关人和打磨者<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup><sup> • </sup><sup>[5](https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim)</sup>。他给范罗苏姆的第一条建议是：为了程序员方便，Python 应当把整数隐式转换为浮点数——这一行为从最初就被采纳<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup>。2018 年，围绕 `:=` 赋值运算符的激烈争论之后，范罗苏姆辞去 BDFL（终身仁慈独裁者）一职，彼得斯在 Python 邮件列表上也不如从前活跃<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup>。

## Timsort：Python 排序背后的算法

Timsort 是一种自适应、稳定、自然的归并排序，名字是彼得斯自己起的，还附了一句“嘿，这是我挣来的”。按他的说法，它在许多种部分有序的数组上有超乎寻常的表现，所需比较次数少于 lg(N!)，最少只需 N−1 次；而在随机数组上，它的速度与 Python 此前经过高度调优的样本排序混合算法一样快<sup>[1](https://github.com/python/cpython/blob/main/Objects/listsort.txt)</sup>。概略地说，主程序从左到右扫过数组一遍，交替地找出下一个游程（run，即一段无法再向两端延伸的已排序区间），并把它智能地并入之前的游程<sup>[1](https://github.com/python/cpython/blob/main/Objects/listsort.txt)</sup>。

2002 年 7 月，彼得斯在 python-dev 邮件列表上发布了一份该算法的详细概述，称其为一种稳定的自然归并排序，在许多轻度乱序的数组上性能优异，在随机数组上与样本排序一样快<sup>[2](https://mail.python.org/pipermail/python-dev/2002-July/026897.html)</sup>。其中一项关键技术"疾驰"（galloping）可追溯到彼得·麦基尔罗伊（Peter McIlroy）1993 年 SODA 会议论文《乐观排序与信息论复杂度》（"Optimistic Sorting and Information Theoretic Complexity"，第 467–474 页，得克萨斯州奥斯汀，1993 年 1 月 25–27 日），也可能更早出自本特利（Bentley）与姚（Yao）的论文<sup>[8](https://bugs.python.org/file4451/timsort.txt)</sup>。

**采用。** Timsort 不仅成为 Python 的标准排序，也成为 Java 标准库的标准排序——在 Java 开发者乔舒亚·布洛赫（Joshua Bloch）看到它对真实世界数据排序的价值之后；范罗苏姆称之为“蒂姆的宏大作品”<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup>。它是 Java 标准库和许多其他框架中的主要排序算法<sup>[9](https://link.springer.com/article/10.1007/s10817-017-9426-4)</sup>，并被用于 OpenJDK、Android 运行时和 V8 JavaScript 引擎<sup>[4](https://pyvideo.org/pycon-us-2023/quicksort-timsort-powersort-algorithmic-ideas-engineering-tricks-and-trivia-behind-cpythons-new-sorting-algorithm.html)</sup>。

**最坏情况的证明来得很晚。** 彼得斯公布了一个最坏情况界，但没有证明它。第一个证明 Python 的 TimSort 最坏情况运行时间为 O(n log n) 的工作，出现在该算法开始取代各大语言中的快速排序十余年之后，由奥热（Auger）、朱热（Jugé）、尼科（Nicaud）和皮沃托（Pivoteau）完成；他们还确立了 Python 的 TimSort 运行时间为 1.5nH + O(n)，其中 H 是游程分布的熵<sup>[6](https://arxiv.org/html/1805.08612v3)</sup>。作为副产品，该分析发现了 Java 实现中的一个缺陷，它可能导致排序在执行过程中失败；Java 版与 Python 版略有不同<sup>[6](https://arxiv.org/html/1805.08612v3)</sup>。另外，用 KeY 工具对 OpenJDK 的 TimSort 进行形式化验证时，发现了一个导致实现因未捕获异常而崩溃的缺陷，并由此推导出一个无缺陷版本，且经过了机器验证<sup>[9](https://link.springer.com/article/10.1007/s10817-017-9426-4)</sup>。

## 《Python 之禅》

1999 年，彼得斯把范罗苏姆的设计品味提炼成一首 19 行的诗，即《Python 之禅》。它相当于 Python 程序员共享的经典文本，Python 的设计者在 PEP 讨论中会引用它<sup>[3](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)</sup>。它开篇是"优美胜于丑陋"，至今仍可通过在 Python 解释器中输入 `import this` 显示出来<sup>[5](https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim)</sup>。

## 其他技术贡献

`timeit` 模块提供了一种简单的方法，为 Python 小段代码计时，既提供命令行接口，也提供函数调用接口，同时避开测量执行时间时的常见陷阱；当前 Python 3.14.6 的文档中记载了该模块，并指向蒂姆·彼得斯为《Python Cookbook》（O'Reilly）第二版“算法”一章所写的导言<sup>[10](https://docs.python.org/3/library/timeit.html)</sup>。

2000 年 10 月，在 Python 2 之前的 python-dev 讨论中，彼得斯反对从头重写这门语言，认为渐进式的工作更可能成功，而把全盘重写项目推销给雇主大概是不可能的<sup>[7](https://lwn.net/2000/1102/a/pythondev.php3)</sup>。

## Timsort 与其他排序算法的比较

学术文献给 Timsort 的成绩单褒贬参半。好的一面是，它的运行时间可证明为 1.5nH + O(n)，也就是说其代价随输入游程结构的熵而自适应<sup>[6](https://arxiv.org/html/1805.08612v3)</sup>。不好的一面是，布斯（Buss）与克诺普（Knop）证明了 Timsort 归并代价的下界为 (1.5 − o(1)) n log n（归并代价是比较次数的上界），并提出了新的稳定自然归并排序——2-归并排序与 α-归并排序，它们的最坏情况归并代价界更好，实现上略为简单，在实验中表现也更佳<sup>[11](https://ar5iv.labs.arxiv.org/html/1801.04641)</sup>。

**归并策略的缺陷。** 一份 PyCon 2023 演讲记录表明，Timsort 合并已检测游程的顺序，其代价可能比必要值高出多达 50%；一个相关缺陷可能导致 CPython 和 Java 中的栈溢出。尽管问题已被修复，但值得注意的是，约十年的广泛使用都未能暴露它。基于最优字母树的 [Powersort](https://www.edgepedia.org/zh/powersort) 归并策略已在 CPython 3.11.0（2022 年）中被采用<sup>[4](https://pyvideo.org/pycon-us-2023/quicksort-timsort-powersort-algorithmic-ideas-engineering-tricks-and-trivia-behind-cpythons-new-sorting-algorithm.html)</sup>。

## 近期进展

Timsort 仍是 Python 的标准排序，彼得斯最初的设计笔记仍保存在当前 CPython 主分支的 `Objects/listsort.txt` 中<sup>[1](https://github.com/python/cpython/blob/main/Objects/listsort.txt)</sup>。`timeit` 的文档及其对《Python Cookbook》的出处标注在 Python 3.14.6 中仍然有效<sup>[10](https://docs.python.org/3/library/timeit.html)</sup>。

**GIL 时代正在终结。** 在启用 GIL 的 CPython 构建中，全局解释器锁阻止多个线程同时执行 Python 代码，是从 Python 高效利用多核 CPU 的障碍；PEP 703 提议将其变为可选，指导委员会接受了该提案，但附带条件是推行须渐进且可逆，GIL 仍是 CPython 构建和 python.org 下载的默认设置<sup>[12](https://peps.python.org/pep-0703/)</sup>。从 3.13 版本起，CPython 支持禁用 GIL 的自由线程构建，允许线程在可用的 CPU 核心上并行运行；在 pyperformance 基准测试套件上，平均开销从 macOS aarch64 上的约 1% 到 x86-64 Linux 系统上的 8% 不等<sup>[13](https://docs.python.org/3/howto/free-threading-python.html)</sup>。3.13 发行说明将该模式描述为实验性的，作为单独的可执行文件发布，通常名为 `python3.13t`，默认不启用，预计单线程性能会有明显损失<sup>[14](https://github.com/python/cpython/blob/main/Doc/whatsnew/3.13.rst)</sup>。指导委员会的分阶段计划是：中期内该构建得到支持但非默认，长期目标是以无 GIL 为默认，这可能需要长达五年<sup>[15](https://discuss.python.org/t/a-steering-council-notice-about-pep-703-making-the-global-interpreter-lock-optional-in-cpython/30474/1)</sup>。在自由线程构建中，`dict`、`list` 和 `set` 等内置类型使用内部锁，其在 Python 层面的行为与 GIL 类似<sup>[13](https://docs.python.org/3/howto/free-threading-python.html)</sup>。

## References

1. [Objects/listsort.txt, Tim Peters' Timsort description, CPython source tree](https://github.com/python/cpython/blob/main/Objects/listsort.txt)
2. [Tim Peters, [Python-Dev] Sorting, python-dev mailing list, July 2002](https://mail.python.org/pipermail/python-dev/2002-July/026897.html)
3. [The Happy Medium: Distinguished Service Award Winner Tim Peters, Python Software Foundation News, 2018](https://pyfound.blogspot.com/2018/07/the-happy-medium-distinguished-service.html)
4. [Quicksort, Timsort, Powersort (PyCon US 2023 talk record), pyvideo.org](https://pyvideo.org/pycon-us-2023/quicksort-timsort-powersort-algorithmic-ideas-engineering-tricks-and-trivia-behind-cpythons-new-sorting-algorithm.html)
5. [Chris McDonough, The Shameful Defenestration of Tim](https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim)
6. [Auger, Jugé, Nicaud, Pivoteau, On the Worst-Case Complexity of TimSort](https://arxiv.org/html/1805.08612v3)
7. [python-dev summary, LWN.net, 2 November 2000](https://lwn.net/2000/1102/a/pythondev.php3)
8. [Timsort write-up, Python bug tracker attachment](https://bugs.python.org/file4451/timsort.txt)
9. [Verifying OpenJDK's Sort Method for Generic Collections, Journal of Automated Reasoning](https://link.springer.com/article/10.1007/s10817-017-9426-4)
10. [timeit — Measure execution time of small code snippets, Python 3.14.6 documentation](https://docs.python.org/3/library/timeit.html)
11. [Buss & Knop, Strategies for Stable Merge Sorting](https://ar5iv.labs.arxiv.org/html/1801.04641)
12. [PEP 703 – Making the Global Interpreter Lock Optional in CPython](https://peps.python.org/pep-0703/)
13. [Python support for free threading, Python 3.14 documentation](https://docs.python.org/3/howto/free-threading-python.html)
14. [What's New in Python 3.13, CPython release notes](https://github.com/python/cpython/blob/main/Doc/whatsnew/3.13.rst)
15. [A Steering Council notice about PEP 703, discuss.python.org](https://discuss.python.org/t/a-steering-council-notice-about-pep-703-making-the-global-interpreter-lock-optional-in-cpython/30474/1)

---
*Initially written Oct 10, 2026 · Edited: Oct 15, 2026; Oct 25, 2026*

Topic: 技术与人造世界 › 工程师与计算机科学家 › 计算机科学家与人工智能研究者 › Researchers in computer systems, networking, security, databases, and programming languages › Programming languages

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/tim-peters-software-engineer

English original: https://www.edgepedia.org/tim-peters-software-engineer
