zoukankan      html  css  js  c++  java
  • 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"


  • 相关阅读:
    Schema和数据类型优化?
    语雀发布博客园
    为知笔记文章目录
    码云搭建博客
    springboot的过滤器、监听器、拦截器
    springboot常用注解
    springboot使用小技巧合集
    springboot整合swagger2
    强制卸载win软件
    xshell下载和优化配置
  • 原文地址:https://www.cnblogs.com/lexus/p/1750524.html
Copyright © 2011-2022 走看看