python3.6json、simplejson(没安装C拓展)、ujson的性能对比uj。。。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
python3.6json、simplejson(没安装C拓展)、ujson的性能对
⽐uj。
测试代码为:
1import time
2import json
3# import ujson
4# import simplejson
5 test_data = {
6'baihe': {
7'name': ('百合', 'utf-8'),
8'say': ('清新,淡雅,花⾹', 'utf-8'),
9'grow_time': 0.5,
10'fruit_time': 0.5,
11'super_time': 0.5,
12'total_time': 1,
13'buy':{'gold':2, } ,
14'harvest_fruit': 1,
15'harvest_super': 1,
16'sale': 1,
17'level_need': 0,
18'experience' : 2,
19'exp_fruit': 1,
20'exp_super': 1,
21'used': True,
22 },
23'1':{
24'interval' : 0.3,
25'probability' : {
26'98': {'chips' : (5, 25), },
27'2' : {'gem' : (1,1), },
28 },
29 },
30'2':{
31'unlock' : {'chips':1000, 'FC':10,},
32'interval' : 12,
33'probability' : {
34'70': {'chips' : (120, 250), },
35'20': {'gem' : (1,1), },
36'10': {'gem' : (2,2), },
37 },
38 },
39'one':{
40'10,5' :{'id':'m01', 'Y':1, 'msg':u'在罐⼦⾥发现了⼀个银币!',},
41'3,7' :{'id':'m02', 'Y':10,'msg':u'发现了⼗个银币!好⼤⼀笔钱!',},
42'15,5' :{'id':'m03', 'Y':2, 'msg':u'⼀只⽼⿏跑了过去',},
43'7,4' :{'id':'m04', 'Y':4, 'msg':u'发现了四个⽣锈的银币……',},
44'2,12' :{'id':'m05', 'Y':6, 'msg':u'六个闪亮的银币!',},
45 },
46 }
47 start_time = time.time()
48print ("start_time:", start_time)
49 j = 1
50while True:
51 j += 1
52 a = json.dumps(test_data)
53# a = ujson.dumps(test_data)
54# a = simplejson.dumps(test_data)
55 data_length = len(a)
56 end_time = time.time()
57if end_time - start_time >= 1 :
58break
59print ("loop_num:", j)
60print ("end_time: ",end_time)
61print (data_length ,a)
查看测试代码
3次测试都在在我的笔记本上测试,即然同⼀配置环境下,:
json 测试3次:
start_time: 1596546865.35845
loop_num: 37571
end_time: 1596546866.3591375
start_time: 1596546903.352182
loop_num: 36305
end_time: 1596546904.3528645
start_time: 1596546945.0092795
loop_num: 38542
end_time: 1596546946.009977
平均数为:(37571+36305+38542)/3= 37472.666666666664
simplejson 测3次:
start_time: 1596547174.9759703
loop_num: 23419
end_time: 1596547175.9766564
start_time: 1596547194.0049856
loop_num: 22503
end_time: 1596547195.0056722
start_time: 1596547248.2294648
loop_num: 23353
end_time: 1596547249.2301195
平均数为:(23419+22503+23353)/3=23091.666666666668
ujson 测试3次:
start_time: 1596547361.6813502
loop_num: 74860
end_time: 1596547362.6820362
start_time: 1596547385.706816
loop_num: 75275
end_time: 1596547386.7074997
start_time: 1596547408.5539103
loop_num: 77128
end_time: 1596547409.5545647
平均数为:(74860+75275+77128)/3=75754.33333333333结果显⽽易见:ujson > json > simplejson(未安装C扩展)。