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

前端 未结 5 1744
梦毁少年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条回答
  •  -上瘾入骨i
    2021-02-15 18:06

    There is a file buffer in the ofstream, this may decrease the times accessing to the disk. in addition, fprintf is a function with variable parameters which will call some va_# functions, but ofstream won't.I think you can use fwrite() or putc() to have a test.

提交回复
热议问题