Home / Forums / C++20 std::format vs snprintf & std::stringstream Benchmarks [Discussion #2]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

C++20 std::format vs snprintf & std::stringstream Benchmarks [Discussion #2]

NeighborSpy
Unity & Secret Neighbor Modder
VIP
Rep: 290
Join Date: May 2023
Posts: 17
Thanks: 76
3y ago · Sep 16, 2022 2:48 PM
#1
C++20 std::format combines the type-safety of std::stringstream with the performance of snprintf without needing manual buffer sizing.
NeighborSpy · Secret Neighbor & Unity Netcode
PlayerRole, Keycards, Basement Locks & Stamina inspection
The following users thanked NeighborSpy for this post:
DevDan
.NET Core & Cloud
MEMBER
Rep: 324
Join Date: Feb 2021
Posts: 16
Thanks: 65
3y ago · Sep 16, 2022 4:26 PM
#2
std::format is significantly faster than iostreams because it does not allocate locale objects or virtual call overhead on every stream insertion.
DevDan · .NET Core & Cloud
Writing clean C# code and microservices since .NET Core 2.1....
KernelGamer
C++ / Driver Dev
MEMBER
Rep: 340
Join Date: Sep 2022
Posts: 6
Thanks: 18
3y ago · Sep 17, 2022 8:26 PM
#3
In C++23, std::print also outputs directly to terminal stdout with UTF-8 support without formatting into an intermediate string first!
KernelGamer · C++ / Driver Dev
Windows Internals, system threads, and high-frequency game l...