码迷,mamicode.com
首页 > 编程语言 > 详细

Python中的ujson模块

时间:2017-11-01 14:52:56      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:res   import   coding   python   *args   pre   imp   fun   结果   

听说ujson比json模块快了很多,特来一试:

# -*- coding: utf-8 -*-
import json
import ujson
import time

def cost_time(func):

    def inner(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        stop_time = time.time()
        print stop_time - start_time
        # print result
        return result

    return inner

a = {}
for i in xrange(1, 1000000):
    a[i] = 1

@cost_time
def json_dumps(obj):
    return json.dumps(obj)

@cost_time
def ujson_dumps(obj):
    return ujson.dumps(obj)


r1 = json_dumps(a)
r2 = ujson_dumps(a)


# 结果
0.245149850845
0.115290880203

果然快了一倍多

 

Python中的ujson模块

标签:res   import   coding   python   *args   pre   imp   fun   结果   

原文地址:http://www.cnblogs.com/MnCu8261/p/7765937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!