Very surprising perfs of fprintf vs std::ofstream (fprintf is very slow)

前端 未结 5 1743
梦毁少年i
梦毁少年i 2021-02-15 17:15

I was running some benchmarks to find the most efficient way to write a huge array to a file in C++ (more than 1Go in ASCII).

So I compared std::ofstream with fprintf (s

5条回答
  •  无人共我
    2021-02-15 17:43

    Have you set sync_with_stdio somewhere upstream of the code you have shown?

    While what you report is opposite that of what is empirically seen, most people think and believe what you see should be the norm. iostreams are type-safe, whereas the printf family of functions are variadic functions that have to infer the types of the va_list from the format specifier.

提交回复
热议问题