Skip to content

Instantly share code, notes, and snippets.

@nekoya
Created May 18, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nekoya/bc30732bf29c19074fd5 to your computer and use it in GitHub Desktop.
Save nekoya/bc30732bf29c19074fd5 to your computer and use it in GitHub Desktop.
from benchmarker import Benchmarker
import json
import ujson
imp_obj = {
'rectangle': {'tagid': '12345', 'banner': {'w': 300, 'h': 250}},
'big_banner': {'tagid': '22222', 'banner': {'w': 728, 'h': 90}},
'rectangle_with_inventory': {'tagid': '10000', 'banner': {'w': 300, 'h': 250}},
'banned': {'tagid': '54321', 'banner': {'w': 300, 'h': 250}},
}
imp_json = json.dumps(imp_obj)
with Benchmarker(width=40, loop=100000) as bm:
for _ in bm('json.dumps'):
json.dumps(imp_obj)
for _ in bm('ujson.dumps'):
ujson.dumps(imp_obj)
for _ in bm('json.loads'):
json.loads(imp_json)
for _ in bm('ujson.loads'):
ujson.loads(imp_json)
"""
## benchmarker: release 3.0.1 (for python)
## python platform: linux2 [GCC 4.6.3]
## python version: 2.7.3
## user sys total real
json.dumps 0.7000 0.0100 0.7100 0.7667
ujson.dumps 0.2700 0.0000 0.2700 0.2850
json.loads 1.3800 0.0000 1.3800 1.4598
ujson.loads 0.2700 0.0000 0.2700 0.2789
## Ranking real
ujson.loads 0.2789 (100.0%) *************************
ujson.dumps 0.2850 ( 97.9%) ************************
json.dumps 0.7667 ( 36.4%) *********
json.loads 1.4598 ( 19.1%) *****
## Ratio Matrix real [01] [02] [03] [04]
[01] ujson.loads 0.2789 100.0% 102.2% 274.9% 523.4%
[02] ujson.dumps 0.2850 97.9% 100.0% 269.0% 512.2%
[03] json.dumps 0.7667 36.4% 37.2% 100.0% 190.4%
[04] json.loads 1.4598 19.1% 19.5% 52.5% 100.0%
## benchmarker: release 3.0.1 (for python)
## python platform: linux2 [PyPy 2.5.1 with GCC 4.6.3]
## python version: 2.7.9
## user sys total real
json.dumps 0.5600 0.0100 0.5700 0.5760
json.loads 0.2500 0.0000 0.2500 0.2596
## Ranking real
json.loads 0.2596 (100.0%) *************************
json.dumps 0.5760 ( 45.1%) ***********
## Ratio Matrix real [01] [02]
[01] json.loads 0.2596 100.0% 221.9%
[02] json.dumps 0.5760 45.1% 100.0%
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment