$ pypy benchmark.py

Array with 256 doubles:
json encode : 5044.67291 calls/sec
json decode : 19591.44018 calls/sec
Array with 256 utf-8 strings:
                                                               json
decode UTF : 71.03748 calls/sec
json decode UTF : 482.03748 calls/sec

$ /usr/bin/python benchmark.py

Array with 256 doubles:

json encode : 4292.39818 calls/sec
json decode : 15089.87792 calls/sec

Array with 256 utf-8 strings:

json encode UTF : 2062.16175 calls/sec
json decode UTF : 479.04892 calls/sec

Test using ultra json:
$ /usr/bin/python ujson/test/benchmark.py


Array with 256 doubles:
ujson encode      : 4386.51907 calls/sec
simplejson encode : 4269.30241 calls/sec
yajl  encode      : 4268.15286 calls/sec
                                                      ujson decode
 : 23814.23743 calls/sec
                                  simplejson decode : 15375.76992
calls/sec
                 yajl decode       : 15388.19165 calls/sec

Array with 256 utf-8 strings:
                                                           ujson
encode      : 4114.12586 calls/sec
                                              simplejson encode :
1965.17111 calls/sec
                              yajl  encode      : 1964.98007 calls/sec

             ujson decode      : 1237.99751 calls/sec

simplejson decode : 440.96787 calls/sec
                                                   yajl decode       :
440.53785 calls/sec




Ofcoz it is not fair comparing against Ultra json but there is no real
performance increase vs vanilla python's json
import json
import sys
from time import time as gettime
import time
import random

"""for complex test"""
user = { "userId": 3381293, "age": 213, "username": "johndoe", "fullname": u"John Doe the Second", "isAuthorized": True, "liked": 31231.31231202, "approval": 31.1471, "jobs": [ 1, 2 ], "currJob": None }
friends = [ user, user, user, user, user, user, user, user ]

decodeData = ""


def simplejsonEnc():
    x = json.dumps(testObject)
    #print "simplejsonEnc", x


"""=========================================================================="""



def simplejsonDec():
    x = json.loads(decodeData)
    #print "simplejsonDec: ", x

"""=========================================================================="""

def timeit_compat_fix(timeit):
    if sys.version_info[:2] >=  (2,6):
        return
    default_number = 1000000
    default_repeat = 3
    if sys.platform == "win32":
        # On Windows, the best timer is time.clock()
        default_timer = time.clock
    else:
        # On most other platforms the best timer is time.time()
        default_timer = time.time
    def repeat(stmt="pass", setup="pass", timer=default_timer,
       repeat=default_repeat, number=default_number):
        """Convenience function to create Timer object and call repeat method."""
        return timeit.Timer(stmt, setup, timer).repeat(repeat, number)
    timeit.repeat = repeat


if __name__ == "__main__":
    import timeit
    timeit_compat_fix(timeit)

print "Array with 256 doubles:"
testObject = []

for x in xrange(256):
    testObject.append(sys.maxint * random.random())
    
COUNT = 10000


print "simplejson encode : %.05f calls/sec" % (COUNT / min(timeit.repeat("simplejsonEnc()", "from __main__ import simplejsonEnc", gettime,10, COUNT)), )


decodeData = json.dumps(testObject)


print "simplejson decode : %.05f calls/sec" % (COUNT / min(timeit.repeat("simplejsonDec()", "from __main__ import simplejsonDec", gettime,10, COUNT)), )

    
    
print "Array with 256 utf-8 strings:"
testObject = []

for x in xrange(256):
    testObject.append("نظام الحكم سلطاني وراثي في الذكور من ذرية السيد تركي بن سعيد بن سلطان ويشترط فيمن يختار لولاية الحكم من بينهم ان يكون مسلما رشيدا عاقلا ًوابنا شرعيا لابوين عمانيين ")

COUNT = 2000



print "simplejson encode UTF : %.05f calls/sec" % (COUNT / min(timeit.repeat("simplejsonEnc()", "from __main__ import simplejsonEnc", gettime,10, COUNT)), )
decodeData = json.dumps(testObject)
print "simplejson decode UTF : %.05f calls/sec" % (COUNT / min(timeit.repeat("simplejsonDec()", "from __main__ import simplejsonDec", gettime,10, COUNT)), )
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to