听说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
果然快了一倍多
no copyright !! 个人原创博客欢迎转载,可以不保留出处。