python 烧瓶用ujson&json基准测试
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 烧瓶用ujson&json基准测试相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python
import timeit
import jsonrpclib
import ujson
import requests
N_TEST = 10000
server_json = jsonrpclib.Server('http://localhost:8000/json/')
server_ujson = jsonrpclib.Server('http://localhost:8000/ujson/')
server_jsonrpclib = jsonrpclib.Server('http://localhost:8080/')
param_1 = "IOOIHIUGOJOIUGIHOHjphogojhpohpjhpjp12p3j1p3j1p4j1p4j1p41jpj414"
param_2 = "IOOIHIUGOJOIUGIHOHjphogojhpohpjhpjp12p3j1p3j1p4j1p4j1p41jpj414"
param_3 = 10
def test_ujson_rpc():
server_ujson.echo_ujson(param_1, param_2, param_3)
def test_json_rpc():
server_json.echo_json(param_1, param_2, param_3)
print "test flask ujson rpc"
t = timeit.Timer(test_ujson_rpc)
print t.timeit(N_TEST)
print "test flask json rpc"
t = timeit.Timer(test_json_rpc)
print t.timeit(N_TEST)
from flask import Flask, request
import ujson
import json
app = Flask(__name__)
@app.route("/ujson/", methods = ["POST"])
def echo_ujson():
req_data = ujson.loads(request.data)
params = req_data['params']
reply = {
"jsonrpc": "2.0",
"result": [params[0], params[1], params[2]],
"id": req_data['id']
}
return ujson.dumps(reply)
@app.route("/json/", methods = ["POST"])
def echo_json():
req_data = json.loads(request.data)
params = req_data['params']
reply = {
"jsonrpc": "2.0",
"result": [params[0], params[1], params[2]],
"id": req_data['id']
}
return json.dumps(reply)
if __name__ == "__main__":
app.run(debug = False, port = 8000)
以上是关于python 烧瓶用ujson&json基准测试的主要内容,如果未能解决你的问题,请参考以下文章
JSON 转储非数字浮点数与 Python 的 ujson 模块
scala upickle / ujson中JSON null的惯用处理
Python中的ujson模块
python 在OpenShift上的python 2.7.8盒式磁带上的常见序列化器的速度测试(pickle,cPickle,ujson,cjson,simplejson,json,yajl,msg
如何使用 ujson 作为 Flask 编码器/解码器?
Python中的ujson包安装错误