Simplify performance overview

This commit is contained in:
Victor Zverovich 2026-09-04 12:28:26 -07:00
parent 8bd6079278
commit ba24da597a

View File

@ -180,35 +180,25 @@ Output on a modern terminal with Unicode support:
![image](https://github.com/fmtlib/fmt/assets/576385/2a93c904-d6fa-4aa6-b453-2618e1c327d7)
# Benchmarks
# Performance
## Speed tests
{fmt} can be tens of percent to 2030 times faster than iostreams and
`sprintf`, especially for numeric formatting. It minimizes dynamic memory
allocations and can optionally [compile format strings](
https://fmt.dev/latest/api/#compile-api) into efficient formatting code.
| Library | Method | Run Time, s |
|-------------------|---------------|-------------|
| libc | printf | 0.66 |
| libc++ | std::ostream | 1.63 |
| {fmt} 12.1 | fmt::print | 0.44 |
| Boost Format 1.88 | boost::format | 3.89 |
| Folly Format | folly::format | 1.28 |
See [format-benchmark](https://github.com/fmtlib/format-benchmark) and
[dtoa-benchmark](https://github.com/fmtlib/dtoa-benchmark) for benchmarks
and methodology.
{fmt} is the fastest of the benchmarked methods, \~50% faster than
`printf`.
**Time per double (smaller is better):**
The above results were generated by building `tinyformat_test.cpp` on
macOS 15.6.1 with `clang++ -O3 -DNDEBUG -DSPEED_TEST -DHAVE_FORMAT`, and
taking the best of three runs. In the test, the format string
`"%0.10f:%04d:%+g:%s:%p:%c:%%\n"` or equivalent is filled 2,000,000
times with output sent to `/dev/null`; for further details refer to the
[source](https://github.com/fmtlib/format-benchmark/blob/master/src/tinyformat-test.cc).
[![Time per double for floating-point formatting methods](
https://github.com/user-attachments/assets/3678bc4a-9405-489e-8ce1-ca702829cdaa)](
https://github.com/fmtlib/dtoa-benchmark)
{fmt} is up to 20-30x faster than `std::ostringstream` and `sprintf` on
IEEE754 `float` and `double` formatting
([dtoa-benchmark](https://github.com/fmtlib/dtoa-benchmark)) and faster
than [double-conversion](https://github.com/google/double-conversion)
and [ryu](https://github.com/ulfjack/ryu):
[![image](https://user-images.githubusercontent.com/576385/95684665-11719600-0ba8-11eb-8e5b-972ff4e49428.png)](https://fmt.dev/unknown_mac64_clang12.0.html)
`ostringstream` and `sprintf` are omitted because they are an order of
magnitude slower than the other methods.
## Compile time and code bloat