# Dhrystone

**Dhrystone** 是一个简短的合成基准测试程序，用于衡量处理器及其编译器的整数（系统编程）性能。它由赖因霍尔德·P·魏克（Reinhold P. Weicker）创建。该程序最初用 Ada 编写，现在主要使用 C 语言。<sup>[1](https://netlib.org/performance/html/dhrystone.intro.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 作者与来源 | 赖因霍尔德·P·魏克，西门子公司；原始论文发表于《ACM 通讯》第 27 卷第 10 期（1984 年 10 月），第 1013–1030 页 |
| 当前版本 | 2.1 版（C、Pascal、Ada），日期为 1988 年 5 月 25 日；原理与测量规则发表于《SIGPLAN 通讯》第 23 卷第 8 期（1988 年 8 月），第 49–62 页<sup>[2](https://github.com/Keith-S-Thompson/dhrystone/blob/master/v2.1/README)</sup> |
| 参考机器 | DEC VAX 11/780，定义为每秒 1757 个 Dhrystone 时等于 1 MIPS<sup>[3](https://docs.amd.com/r/en-US/xd071-versal-dhrystone-benchmark/Performance-Calculation)</sup> |
| 得分公式 | DMIPS = 每秒 Dhrystone 数 / 1757；通常以 DMIPS/MHz 形式报告<sup>[3](https://docs.amd.com/r/en-US/xd071-versal-dhrystone-benchmark/Performance-Calculation)</sup> |
| 规模 | 约 100 条高级语言语句，1–1.5 KB 代码；可完全装入 L1 缓存，因此缓存之外的存储系统未得到测试<sup>[1](https://netlib.org/performance/html/dhrystone.intro.html)</sup> |
| 已知偏差 | 字符串操作（strcpy、strcmp）占比过高，在 C 版本中约占执行时间的 16.1%<sup>[1](https://netlib.org/performance/html/dhrystone.intro.html)</sup><sup> • </sup><sup>[4](https://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/weicker.pdf)</sup> |
| 状态 | 1 版结果已废弃；作者警告称“依赖 MIPS V1.1 数据可能危及你的职业生涯”<sup>[1](https://netlib.org/performance/html/dhrystone.intro.html)</sup> |

## 设计与目的

魏克将 Dhrystone 构建为一个合成基准测试：程序并非运行真实应用，而是一个固定的语句循环，其语句组合反映了已发表的关于系统编程中编程语言构造使用频率的统计数据。该基准测试涵盖过程调用、指针与记录操作、条件判断，以及字符串赋值与比较。其结果是一个速率——每秒完成的 Dhrystone 循环迭代次数（“Dhrystones”）。<sup>[3](https://docs.amd.com/r/en-US/xd071-versal-dhrystone-benchmark/Performance-Calculation)</sup>

该程序刻意保持小巧：约 100 条高级语句，1–1.5 KB 代码。这在 1980 年代初的机器上是一种务实的选择，但也带来了后果。其工作集可装入几乎所有后续处理器的缓存内部，因此该基准测试从未触及一级缓存之外的存储系统，而其小巧的规模也使编译器很容易对其进行优化。<sup>[1](https://netlib.org/performance/html/dhrystone.intro.html)</sup>

## 版本与编译器问题

**1 版与死代码。** 在 1 版中，计算结果既不打印也不使用，因此优化编译器可以将许多语句识别为死代码并抑制其代码生成。1.1 版因此留下了“过多空间，使结果可能因死代码消除而失真”，最先进的编译器可以消除基准测试中过多的部分。<sup>[4](https://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/weicker.pdf)</sup><sup> • </sup><sup>[1](https://netlib.org/performance/html/dhrystone.intro.html)</sup> 后来的一项分析指出，2.1 版在受影响的分支中添加了代码以防止其被消除，并将测量循环的循环检查移入基准测试本身以提高准确性。<sup>[5](https://www.sra.uni-hannover.de/Publications/2000/brehm_00_habilitation.pdf)</sup>

**2 版与 2.1 版。** 2 版于 1988 年 8 月在《SIGPLAN 通讯》上连同测量规则一起发表，纠正了死代码问题，同时保持已执行语句的顺序和分布不变。2.1 版日期为 1988 年 5 月 25 日，与 2.0 版仅在一些小修正上有所不同，不改变执行时间行为。<sup>[2](https://github.com/Keith-S-Thompson/dhrystone/blob/master/v2.1/README)</sup><sup> • </sup><sup>[6](https://www.netlib.org/benchmark/dhry-c)</sup> 魏克本人也承认该工具的局限：“我并不声称 Dhrystone 是衡量微处理器整数性能的完美工具”，并指出基准测试的巨大成功本身就是一种危险，因为人们可能会针对它调整编译器和硬件，从而使其变得不那么有用。<sup>[6](https://www.netlib.org/benchmark/dhry-c)</sup>

## 评分：Dhrystones、DMIPS 与 DMIPS/MHz

参考机器是 DEC VAX 11/780，它被宣布为 1 MIPS 机器，每秒运行 1757 个 Dhrystone。因此，Dhrystone 结果通常除以 1757 转换为 MIPS：<sup>[7](https://www.compuphase.com/dhrystone.htm)</sup><sup> • </sup><sup>[3](https://docs.amd.com/r/en-US/xd071-versal-dhrystone-benchmark/Performance-Calculation)</sup>

\[ \mathrm{DMIPS} = \frac{\text{每秒 Dhrystone 数}}{1757} \]

所得数值称为 Dhrystone MIPS（DMIPS），以区别于原始指令吞吐量。由于现代处理器运行[时钟频率](https://www.edgepedia.org/zh/clock-rate)差异很大，结果通常归一化为 DMIPS/MHz，即每个时钟周期的效率数值。AMD 的 Versal Dhrystone 用户指南给出了一个计算示例：每秒 14,285,565 个 Dhrystone 除以 1757 得到 8130.6573 DMIPS，在 1400 MHz CPU 频率下即为 5.80 DMIPS/MHz。<sup>[3](https://docs.amd.com/r/en-US/xd071-versal-dhrystone-benchmark/Performance-Calculation)</sup> 广泛分发的软件中也使用相同的转换；例如，[HTCondor](https://www.edgepedia.org/zh/htcondor) 项目的 condor_mips 工具就是 Dhrystone 2.1 的一个实现，其结果除以 1757 得到 VAX MIPS。<sup>[8](https://heprcdocs.phys.uvic.ca/reports/matthewMurray-wtr.pdf)</sup>

## 测量规则

由于基准测试规模小且对编译器敏感，魏克发布了用户在进行结果比较时应遵循的基本规则：<sup>[4](https://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/weicker.pdf)</sup>

1. 使用 2.1 版；1.1 版结果因死代码消除而失真。<sup>[4](https://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/weicker.pdf)</sup>
2. 分别编译两个模块，不要内联（合并）用户过程；在 [ANSI C](https://www.edgepedia.org/zh/ansi-c) 下，字符串函数等库例程的内联仍然允许。<sup>[4](https://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/weicker.pdf)</sup>
3. 比较处理器时，双方应使用相同的编程语言和相同程度的编译器优化，因为优化差异可能掩盖 CPU 速度差异。<sup>[4](https://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/weicker.pdf)</sup>

字符串操作是主要的敏感点。在 C 中，字符串赋值和比较是库函数（strcpy 和 strcmp），必须检查每个字节以寻找空终止符，而 Ada 和 Pascal 编译器可以生成高效的内联字指令，因为字符串长度在编译时已知；在同等质量的编译器下，Pascal 和 Ada 的数值可能好约 10%。在 C 版本的执行剖面中，strcpy 和 strcmp 合计约占 16.1% 的时间，因此该基准测试对 C 库的测试几乎不亚于对编译器的测试。<sup>[4](https://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/weicker.pdf)</sup><sup> • </sup><sup>[6](https://www.netlib.org/benchmark/dhry-c)</sup> 魏克承认，该基准测试的字符串比较在扫描 20 个字符后才终止，比真实程序中的大多数字符串比较更晚，但为了与原始版本保持一致而保留了该行为。<sup>[6](https://www.netlib.org/benchmark/dhry-c)</sup>

## 批评与实际地位

反复出现的批评是：Dhrystone 包含库调用，使得比较依赖于库的质量；聪明的编译器可以针对 Dhrystone 性能进行调优；而且由于其占用空间小，可装入 L1 缓存，无法测试存储子系统。<sup>[9](https://www.sciencedirect.com/topics/computer-science/dhrystone)</sup> 一项微处理器基准测试调查还指出，基准测试环境（包括编译器开关和库）往往未披露，且由于缺乏标准组织，原始运行规则已被侵蚀，使得测量容易被规避。<sup>[10](https://upcommons.upc.edu/server/api/core/bitstreams/c043cc73-65a5-4cd0-a722-9ac85a7c5f50/content)</sup> 理查德·约克（Richard York）的 ARM 白皮书《情境中的基准测试：Dhrystone》（2002 年）认为，该基准测试不太适合预测嵌入式系统软件的性能，而一项嵌入式案例研究发现，两方在表面上已记录的条件下运行同一基准测试，结果之比可能达到五比一。<sup>[7](https://www.compuphase.com/dhrystone.htm)</sup>

尽管有这些批评，Dhrystone 在嵌入式计算领域仍在使用，其极小的占用空间适合小型微控制器和定制处理器内核。<sup>[11](https://booksite.elsevier.com/9780128017333/content/Section%201-12_Hist%20Persp.pdf)</sup> 其长寿命也使其可用于历史比较：2025 年，Windows 开发者戴夫·普拉默（Dave Plummer）在 1976 年至 2023 年间发布的 25 台计算机上未经修改地运行了 K&R C Dhrystone 测试，测得单线程性能差异达 20 万倍，同时指出该数值低估了现代进步，因为该基准测试是单线程的、使用简单数学运算，且从不离开缓存。<sup>[12](https://www.tomshardware.com/pc-components/cpus/veteran-devs-newest-computer-is-200-000-times-faster-than-his-oldest-in-custom-benchmarks-single-thread-dhrystone-performance-charted-across-25-systems-released-between-1976-and-2023)</sup>

Dhrystone 的 netlib 发行版仍带有作者本人的建议：仅将其用于受控实验，不要盲目相信某处引用的单个 Dhrystone MIPS 数值。<sup>[1](https://netlib.org/performance/html/dhrystone.intro.html)</sup>

## References

1. [Dhrystone introduction and results table, netlib](https://netlib.org/performance/html/dhrystone.intro.html)
2. [Dhrystone 2.1 README, Keith-S-Thompson/dhrystone, GitHub](https://github.com/Keith-S-Thompson/dhrystone/blob/master/v2.1/README)
3. [Performance Calculation, Versal Dhrystone Benchmark User Guide (XD071), AMD](https://docs.amd.com/r/en-US/xd071-versal-dhrystone-benchmark/Performance-Calculation)
4. [Reinhold P. Weicker. An overview of common benchmarks. Computer.](https://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/weicker.pdf)
5. [Brehm, habilitation thesis, University of Hannover](https://www.sra.uni-hannover.de/Publications/2000/brehm_00_habilitation.pdf)
6. [Dhrystone C version 2.1 distribution (RATIONALE and source), netlib](https://www.netlib.org/benchmark/dhry-c)
7. [The Dhrystone benchmark, the LPC2106 and GNU GCC, CompuPhase](https://www.compuphase.com/dhrystone.htm)
8. [The Benchmarks (condor_mips), University of Victoria technical report](https://heprcdocs.phys.uvic.ca/reports/matthewMurray-wtr.pdf)
9. [Dhrystone: an overview, ScienceDirect Topics](https://www.sciencedirect.com/topics/computer-science/dhrystone)
10. [Benchmarks of different microprocessors, UPC](https://upcommons.upc.edu/server/api/core/bitstreams/c043cc73-65a5-4cd0-a722-9ac85a7c5f50/content)
11. [Historical perspectives section, Elsevier computer architecture text](https://booksite.elsevier.com/9780128017333/content/Section%201-12_Hist%20Persp.pdf)
12. [Veteran dev's newest computer is '200,000 times' faster than his oldest in custom benchmarks, Tom's Hardware](https://www.tomshardware.com/pc-components/cpus/veteran-devs-newest-computer-is-200-000-times-faster-than-his-oldest-in-custom-benchmarks-single-thread-dhrystone-performance-charted-across-25-systems-released-between-1976-and-2023)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Microarchitecture & implementation › CPU utilities and tools

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/dhrystone

English original: https://www.edgepedia.org/dhrystone
