Fastest stdin/out IO in python 3?

后端 未结 3 740
Happy的楠姐
Happy的楠姐 2021-01-01 15:28

I\'ve been solving a few problems on SPOJ.pl using python 3.1.2 and some peoples fast result on simple problems makes me wonder if there is a faster way to handle input and

3条回答
  •  遥遥无期
    2021-01-01 16:01

    The following will probably be fastest:

    1. Read all the input at once using os.read(0, some_big_enough_number).

    2. Process the output, collecting the results in a list results.

    3. Write all the output at once using os.write(1, "".join(results)).

    I remember one case where I noticed that os.read() and os.write() are sometimes faster than using Python I/O, but I don't remember the details.

提交回复
热议问题