json seralization is more slower than cpickle

http://oldj.net/article/python-pickle/
i like use jsonpy than py2.6 embedded json lib,beacause it is more friendly for unicode
reference
http://oldj.net/article/python-pickle/


some write style i record here:
import jsonpy
import os.path
import cPickle as pickle
import time
if os.path.exists("cache.pickle"):
    it=time.time()
    cache= pickle.load(open("cache.pickle", "rb"))
    print "cost time:%ss"%(time.time()-it)
    print "直接从cache.pickle载入"
    print len(cache)
if os.path.exists("cache.txt") and (not os.path.exists("cache.pickle")):
    print "从cache.txt载入"
    cc=0
    itit=time.time()
    for line in open("cache.txt","r").readlines():
        cc+=1
        print cc
        k,v=line.strip().split("||||||")
        #print type(jsonpy.read(v))
        cache[k]=jsonpy.read(v)
    print "载入缓存成功"
    print "cost time:%ss"%(time.time()-itit)
    print len(cache)
    from lib import filehelper
    if filehelper.hasfile("cache.pickle"):
        filehlper.delfile("cache.pickle")
        print "删除先前的cache.pickle"
    pickle.dump(cache, open("cache.pickle", "wb"), True)
    print "导出成cache.pickle"


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值