Faster I/O in C

后端 未结 8 1921
自闭症患者
自闭症患者 2021-02-09 04:40

I have a problem which will take 1000000 lines of inputs like below from console.

0 1 23 4 5
1 3 5 2 56
12 2 3 33 5
...
...

I have used scanf,

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 05:15

    Read a line at a time (if buffer not big enough for a line, expand and continue with larger buffer).

    Then use dedicated functions (e.g. atoi) rather than general for conversion.

    But, most of all, set up a repeatable test harness with profiling to ensure changes really do speed things up.

提交回复
热议问题