Why is StringIO object slower than real file object?

后端 未结 3 936
无人共我
无人共我 2021-01-12 11:36

I\'m looking through the source of StringIO where it says says some notes:

  1. Using a real file is often faster (but less convenient)
3条回答
  •  太阳男子
    2021-01-12 11:46

    It is not neccessarily obvious from the source but python file objects is built straight on the C library functions, with a likely small layer of python to present a python class, or even a C wrapper to present a python class. The native C library is going to be highly optimised to read bytes and blocks from disk. The python StringIO library is all native python code - which is slower than native C code.

提交回复
热议问题