json seralization is more slower than cpickle
2010-06-03 09:58
465 查看
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"
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"
相关文章推荐
- Mysql错误:The server time zone value is unrecognized or represents more than one time zone
- What you can do is more important than who your parents are.
- Love is more than a word
- This version of the rendering library is more recent than your version of ADT pl
- mysql连接异常:The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zo
- Why Free Software Is More Important Now Than Ever Before
- This version of the rendering library is more recent than your version of Android Studio. Please upd
- Xquery:There is more than one method matching the function 异常处理
- Flex中TypeError: Error #1089: Assignment to lists with more than one item is not supported.
- QA is more than Testing
- #One paper per week# Anger Is More Influential than Joy: Sentiment Correlation in Weibo
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- the rendering library is more recent than your version of android studio
- Why is FSB Slower than CPU internal speed?
- This version of the rendering library is more recent than your version of IntelliJ IDEA.
- You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed问题解决
- This version of the rendering library is more recent than your version of ADT plug-in. Please updat
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- the rendering library is more recent than your version of android studio
- ORA-01207:file is more recent than control file - old control file