printf slows down my program

后端 未结 9 770
旧巷少年郎
旧巷少年郎 2020-12-14 01:55

I have a small C program to calculate hashes (for hash tables). The code looks quite clean I hope, but there\'s something unrelated to it that\'s bugging me.

I can e

9条回答
  •  半阙折子戏
    2020-12-14 02:45

    I discovered long ago using this technique something that should have been obvious. Not only is I/O slow, especially to the console, but formatting decimal numbers is not fast either. If you can put the numbers in binary into big buffers, and write those to a file, you'll find it's a lot faster.

    Besides, who's going to read them? There's no point printing them all in a human-readable format if nobody needs to read all of them.

提交回复
热议问题