printf slows down my program

后端 未结 9 748
旧巷少年郎
旧巷少年郎 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条回答
  •  萌比男神i
    2020-12-14 02:35

    If you are printf()ing to the console it's usually extremely slow. I'm not sure why but I believe it doesn't return until the console graphically shows the outputted string. Additionally you can't mmap() to stdout.

    Writing to a file should be much faster (but still orders of magnitude slower than computing a hash, all I/O is slow).

提交回复
热议问题