Comparison between python JSON performance testing and simplejson, jsonsimplejson

Source: Internet
Author: User

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
  1. #! /Usr/bin/env python
  2. # Coding = UTF-8
  3. Import time
  4. Import json
  5. Test_data = {
  6. 'Route he ':{
  7. 'Name': unicode ('lily', 'utf-8 '),
  8. 'Server': unicode ('fresh, elegant, floral, 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. 'Bability ':{
  26. '98 ': {'chips': (5, 25 ),},
  27. '2': {'gem ),},
  28. },
  29. },
  30. '2 ':{
  31. 'Unlock': {'chips ': 1000, 'fc': 10 ,},
  32. 'Interval': 12,
  33. 'Bability ':{
  34. '70': {'chunk': (120,250 ),},
  35. '20': {'gem ),},
  36. '10': {'gem ': (2, 2 ),},
  37. },
  38. },
  39. 'One ':{
  40. '10, 5': {'id': 'm01', 'y': 1, 'msg ': U' found a silver coin in the jar! ',},
  41. '3, 7': {'id': 'm02', 'y': 10, 'msg ': U' found ten silver coins! A huge amount of money! ',},
  42. '15, 5': {'id': 'm03', 'y': 2, 'msg ': U' a mouse ran past ',},
  43. '7, 4': {'id': 'm04 ', 'y': 4, 'msg': U' found four Rusty silver coins ...... ',},
  44. '2, 12': {'id': 'm05 ', 'y': 6, 'msg': U' six shiny silver coins! ',},
  45. },
  46. }
  47. Start_time = time. time ()
  48. Print "start_time:", start_time
  49. J = 1
  50. While True:
  51. J + = 1
  52. A = json. dumps (test_data)
  53. Data_length = len ()
  54. End_time = time. time ()
  55. If end_time-start_time> = 1:
  56. Break
  57. Print "loop_num:", j
  58. Print "end_time:", end_time
  59. Print data_length,

 

Summary: python's built-in json is acceptable in terms of performance. Simplejson, without C extension acceleration, is extremely inefficient.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.