关于序列化大小的比较

#! /usr/bin/env python
#coding=utf-8
import pickle
import cPickle
#6.6M
def searlize_to_txt():
    f=open("searlize.txt","w")
    for i in xrange(1,1000000):
        f.write("%s\n"%i)
    f.close()
    print "done!"
#8.5M    
def searlize_to_binary():
    list=[i for i in xrange(1,1000000)]
    pickle.dump(list,open("searlize.bin","w"))
    
#8.5M
def searlize_to_binary2():
    list=[i for i in xrange(1,1000000)]
    cPickle.dump(list,open("searlize2.bin","w"))
if __name__ == '__main__':
    searlize_to_binary2()
    #searlize_to_binary()
    #searlize_to_txt()

你可能感兴趣的:(序列化)