[Bugs] #3142 UNSP: Use JSON implementations in Python's standard library instead of cjson
Sugar Labs Bugs
bugtracker-noreply at sugarlabs.org
Mon Mar 5 08:36:36 EST 2012
#3142: Use JSON implementations in Python's standard library instead of cjson
------------------------------------------+---------------------------------
Reporter: erikos | Owner: erikos
Type: defect | Status: new
Priority: Unspecified by Maintainer | Milestone: Unspecified by Release Team
Component: sugar | Version: Unspecified
Severity: Unspecified | Keywords:
Distribution: Unspecified | Status_field: Unconfirmed
------------------------------------------+---------------------------------
Comment(by manuq):
Seems like simplejson replaced the stdlib json in Python 2.6. If we want
to be compatible with Python 2.4, we should perform a check and import
simplejson instead. They are interchangeable, share the same API.
In Python 2.7, json seems faster for this simple test case:
{{{
[manuq at manuq-laptop olpc]$ python /usr/lib/python2.7/timeit.py -s "import
json; d=dict(a=3, b=4)" "json.dumps(d)"
10000 loops, best of 3: 49.7 usec per loop
[manuq at manuq-laptop olpc]$ python /usr/lib/python2.7/timeit.py -s "import
simplejson as json; d=dict(a=3, b=4)" "json.dumps(d)"
10000 loops, best of 3: 51.5 usec per loop
[manuq at manuq-laptop olpc]$
}}}
In Python 2.6, simplejson is a bit faster:
{{{
facundo at phenomenux:~$ timeit.py -s "import json; d=dict(a=3, b=4)"
"json.dumps(d)"
10000 loops, best of 3: 21.4 usec per loop
facundo at phenomenux:~$ timeit.py -s "import simplejson as json; d=dict(a=3,
b=4)" "json.dumps(d)"
100000 loops, best of 3: 9.5 usec per loop
facundo at phenomenux:~$ timeit.py -s "import json; s=json.dumps(dict(a=3,
b=4))" "json.loads(s)"
10000 loops, best of 3: 52.9 usec per loop
facundo at phenomenux:~$ timeit.py -s "import simplejson as json;
s=json.dumps(dict(a=3, b=4))" "json.loads(s)"
100000 loops, best of 3: 5.71 usec per loop
}}}
--
Ticket URL: <http://bugs.sugarlabs.org/ticket/3142#comment:4>
Sugar Labs <http://sugarlabs.org/>
Sugar Labs bug tracking system
More information about the Bugs
mailing list