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

前端 未结 5 1742
梦毁少年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 18:03

    fprintf("%d" requires runtime parsing of the format string, once per integer. ostream& operator<<(ostream&, int) is resolved by the compiler, once per compilation.

提交回复
热议问题