Skip to content

Conversation

@lemire
Copy link
Member

@lemire lemire commented Feb 2, 2026

Fixes #50

This follows comments by a few people, including @vitaut (the fmt author).

These changes drastically change change the performance of fmt, for the better.

On my Apple M4.... before...

./build/benchmarks/benchmark -f data/canada.txt
fmt_format                    :   586.68 MB/s (+/- 6.6 %)     1.87 MB     28.64 ns/f    34.92 Mfloat/s

after...

./build/benchmarks/benchmark -f data/canada.txt 
fmt_format                    :   906.36 MB/s (+/- 4.7 %)     1.87 MB     18.54 ns/f    53.95 Mfloat/s

In context, this makes (in one test), the fmt library much closer to std::to_chars.

dragon4                       :   111.95 MB/s (+/- 3.1 %)     1.87 MB    150.06 ns/f     6.66 Mfloat/s
netlib                        :    20.57 MB/s (+/- 0.9 %)     1.87 MB    816.58 ns/f     1.22 Mfloat/s
fmt_format                    :   582.34 MB/s (+/- 5.6 %)     1.87 MB     28.85 ns/f    34.66 Mfloat/s
grisu3                        :   701.22 MB/s (+/- 9.1 %)     1.87 MB     23.96 ns/f    41.74 Mfloat/s
grisu_exact                   :  1235.86 MB/s (+/- 8.8 %)     2.09 MB     15.21 ns/f    65.74 Mfloat/s
schubfach                     :  1389.48 MB/s (+/- 10.1 %)     1.87 MB     12.09 ns/f    82.71 Mfloat/s
dragonboxlm                   :  2319.66 MB/s (+/- 11.6 %)     2.20 MB      8.54 ns/f   117.15 Mfloat/s
dragonbox                     :  1985.19 MB/s (+/- 10.3 %)     2.09 MB      9.47 ns/f   105.60 Mfloat/s
ryu                           :  1551.55 MB/s (+/- 8.0 %)     2.09 MB     12.12 ns/f    82.53 Mfloat/s
teju_jagua                    :  1569.40 MB/s (+/- 9.1 %)     2.20 MB     12.62 ns/f    79.26 Mfloat/s
swiftDtoa                     :  1059.53 MB/s (+/- 10.0 %)     1.87 MB     15.86 ns/f    63.07 Mfloat/s
yy_double                     :  2038.28 MB/s (+/- 10.8 %)     1.87 MB      8.24 ns/f   121.32 Mfloat/s
std::to_chars                 :  1078.68 MB/s (+/- 9.9 %)     1.87 MB     15.57 ns/f    64.21 Mfloat/s

Context: Daniel Lemire, "Converting floats to strings quickly," in Daniel Lemire's blog, February 1, 2026, https://lemire.me/blog/2026/02/01/converting-floats-to-strings-quickly/.

@lemire lemire requested a review from jaja360 February 2, 2026 20:02
@vitaut
Copy link

vitaut commented Feb 2, 2026

Thanks for updating {fmt} usage!

@lemire
Copy link
Member Author

lemire commented Feb 2, 2026

@vitaut Your comments on our work are much appreciated.

Copy link
Collaborator

@jaja360 jaja360 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I observe ~30% speedup with the new version on my CPU.
PR looks reasonable. We can merge !

@vitaut
Copy link

vitaut commented Feb 3, 2026

Note that {fmt} uses Dragonbox so it's interesting to see a big gap between the two, even after the update. Some gap is expected because {fmt} is a higher-level facility but it's normally much smaller, e.g. on Milo Yip's dtoa-benchmark the gap is ~8%. I would investigate further but the FP implementation in {fmt} is about to be revamped (Dragonbox replaced with https://github.com/vitaut/zmij) so it's probably doesn't matter except that I would recommend adding version information since there is substantial difference between versions and even different algorithms used.

@jaja360
Copy link
Collaborator

jaja360 commented Feb 3, 2026

@vitaut I added fmt version number in the last commit. Thanks for the comment. I also added zmij, see #52. Your algorithm is the fastest on our benchmark. Congrats 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update to fmt 12

4 participants