Comparison between python JSON performance testing and simplejson, jsonsimplejson
After a simple testJSON, That is, the json processing library that comes with python2.6 or above, the efficiency is still acceptable:
1 k Data, 36898 GHz CPU, single core per second dump: Times. It is about 5 times that of pyamf. However, the data volume is large, which is about 1.67 times (1101/656) of pyamf ).
Start_time: 1370747463.77
Loop_num: 36898
End_time: 1370747464.78
Let's take a look.SimplejsonIf the C extension is not installed:
Simplejson, without the C extension installed, I was surprised by the result:
Start_time: 1370748132.87
Loop_num: 1361
End_time: 1370748133.88
The efficiency is so low.
The following is the test code:
[Python]View plaincopy
- #! /Usr/bin/env python
- # Coding = UTF-8
- Import time
- Import json
- Test_data = {
- 'Route he ':{
- 'Name': unicode ('lily', 'utf-8 '),
- 'Server': unicode ('fresh, elegant, floral, utf-8 '),
- 'Grow _ time': 0.5,
- 'Fruit _ time': 0.5,
- 'Super _ time': 0.5,
- 'Total _ time': 1,
- 'Buy': {'gold': 2 ,},
- 'Harvest _ fruit': 1,
- 'Harvest _ super': 1,
- 'Sale': 1,
- 'Level _ need': 0,
- 'Experience ': 2,
- 'Exp _ fruit ': 1,
- 'Exp _ super': 1,
- 'Used': True,
- },
- '1 ':{
- 'Interval': 0.3,
- 'Bability ':{
- '98 ': {'chips': (5, 25 ),},
- '2': {'gem ),},
- },
- },
- '2 ':{
- 'Unlock': {'chips ': 1000, 'fc': 10 ,},
- 'Interval': 12,
- 'Bability ':{
- '70': {'chunk': (120,250 ),},
- '20': {'gem ),},
- '10': {'gem ': (2, 2 ),},
- },
- },
- 'One ':{
- '10, 5': {'id': 'm01', 'y': 1, 'msg ': U' found a silver coin in the jar! ',},
- '3, 7': {'id': 'm02', 'y': 10, 'msg ': U' found ten silver coins! A huge amount of money! ',},
- '15, 5': {'id': 'm03', 'y': 2, 'msg ': U' a mouse ran past ',},
- '7, 4': {'id': 'm04 ', 'y': 4, 'msg': U' found four Rusty silver coins ...... ',},
- '2, 12': {'id': 'm05 ', 'y': 6, 'msg': U' six shiny silver coins! ',},
- },
- }
- Start_time = time. time ()
- Print "start_time:", start_time
- J = 1
- While True:
- J + = 1
- A = json. dumps (test_data)
- Data_length = len ()
- End_time = time. time ()
- If end_time-start_time> = 1:
- Break
- Print "loop_num:", j
- Print "end_time:", end_time
- Print data_length,
Summary: python's built-in json is acceptable in terms of performance. Simplejson, without C extension acceleration, is extremely inefficient.