c++ - Benchmarking linefeed characters vs std::endl -
c++ - Benchmarking linefeed characters vs std::endl -
i'm reading “\n” or '\n' or std::endl std::cout?. despite consensus doesn't matter choose, decided build contrived test measure programme execution speed of each. here simple program:
#include <iostream> int main() { (std::size_t = 0; < iters; ++i) { #ifdef ver1 std::cout << "\n"; #endif #ifdef ver2 std::cout << '\n'; #endif #ifdef ver3 std::cout << std::endl; #endif } } using 1 billion iterations , -o3 , redirecting output /dev/null/, these results:
"\n" 0:30.96 '\n' 0:31.66 with -o2:
"\n" 0:32.96 '\n' 0:31.54 why higher optimization level create '\n' slower?
with setup, you're measuring test run happened interrupted longest thread scheduler. also, imagine might different times writing real file instead of /dev/null.
c++
Comments
Post a Comment