Why is a StringIO object slower than a real object?

I am looking through a source StringIOwhere a few comments are made:

  • Using a real file is often faster (but less convenient) .
  • There is also a faster implementation in C called cStringIO, but these are not subclasses.

StringIO as an object of a memory file, why is it slower than a real file?

+4
source share
3 answers

Python File Handling is fully implemented in the C . This means that it is pretty fast (at least in the same order as its own C code).

StringIO, , Python. , .

, cStringIO , , . , , , C.

+1

, python C, python, python C, python. C . python StringIO - python, , C-.

0

Python: BytesIO Python *, , StringIO, /.

, StringIO , - StringIO ( ). , , cStringIO. . .

, StringIO ""? StringIO , str unicode. , , . , tdelaney answer , (, 10-100x) , , , .

BytesIO , () bytearray. , , cStringIO, , , . , , C .

* Well, version B _pyio, anyway. The standard version of the library is iowritten in C.

0
source

All Articles