marshal dumps faster, cPickle loads faster

后端 未结 6 767
再見小時候
再見小時候 2020-12-09 04:24

I\'m implementing a program that needs to serialize and deserialize large objects, so I was making some tests with pickle, cPickle and marsha

6条回答
  •  Happy的楠姐
    2020-12-09 05:10

    You can make cPickle cca. 50x (!) faster by creating instance of cPickle.Pickler and then setting undocumented option 'fast' to 1:

    outfile = open('outfile.pickle')
    fastPickler = cPickle.Pickler(outfile, cPickle.HIGHEST_PROTOCOL)
    fastPickler.fast = 1
    fastPickler.dump(myHugeObject)
    outfile.close()
    

    But if your myHugeObject has cyclic references, the dump method will never end.

提交回复
热议问题