Fastest way to store large files in Python

前端 未结 5 2045
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 09:45

I recently asked a question regarding how to save large python objects to file. I had previously run into problems converting massive Python dictionaries into string and writing

5条回答
  •  [愿得一人]
    2021-02-04 10:19

    Python code would be extremely slow when it comes to implementing data serialization. If you try to create an equivalent to Pickle in pure Python, you'll see that it will be super slow. Fortunately the built-in modules which perform that are quite good.

    Apart from cPickle, you will find the marshal module, which is a lot faster. But it needs a real file handle (not from a file-like object). You can import marshal as Pickle and see the difference. I don't think you can make a custom serializer which is a lot faster than this...

    Here's an actual (not so old) serious benchmark of Python serializers

提交回复
热议问题