1
0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-11-24 05:12:02 +01:00

Changed default recursion limit. Added new benchmark

This commit is contained in:
Jonas Trnstrm 2012-01-27 15:25:12 +01:00
parent 6b0bc7c623
commit 5950848bf9
5 changed files with 3393 additions and 10 deletions

64
python/benchmark2.py Normal file

@ -0,0 +1,64 @@
# coding=UTF-8
import simplejson
import ujson
import sys
try:
import json
except ImportError:
json = simplejson
import cjson
from time import time as gettime
import time
import sys
import random
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
def ujsonDec():
x = ujson.loads(decodeData)
def simplejsonDec():
x = simplejson.loads(decodeData)
def ujsonEnc():
x = ujson.dumps(encodeData)
def simplejsonEnc():
x = simplejson.dumps(encodeData)
if __name__ == "__main__":
import timeit
timeit_compat_fix(timeit)
COUNT = 100
# Load file into memory
f = open("sample.json", "rb")
decodeData = f.read()
f.close()
encodeData = simplejson.loads(decodeData)
# Decode 1 million times
print "ujson decode : %.05f calls/sec" % (COUNT / min(timeit.repeat("ujsonDec()", "from __main__ import ujsonDec", gettime,10, COUNT)), )
print "simplejson decode : %.05f calls/sec" % (COUNT / min(timeit.repeat("simplejsonDec()", "from __main__ import simplejsonDec", gettime,10, COUNT)), )
print "ujson encode : %.05f calls/sec" % (COUNT / min(timeit.repeat("ujsonEnc()", "from __main__ import ujsonEnc", gettime,10, COUNT)), )
print "simplejson encode : %.05f calls/sec" % (COUNT / min(timeit.repeat("simplejsonEnc()", "from __main__ import simplejsonEnc", gettime,10, COUNT)), )

@ -690,14 +690,7 @@ PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs)
PyObject *oensureAscii = NULL;
int idoublePrecision = 5; // default double precision setting
PRINTMARK();
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi", kwlist, &oinput, &oensureAscii, &idoublePrecision))
{
return NULL;
}
JSONObjectEncoder encoder =
JSONObjectEncoder encoder =
{
Object_beginTypeContext, //void (*beginTypeContext)(JSOBJ obj, JSONTypeContext *tc);
Object_endTypeContext, //void (*endTypeContext)(JSOBJ obj, JSONTypeContext *tc);
@ -719,11 +712,22 @@ PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs)
1, //forceAscii
};
PRINTMARK();
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi", kwlist, &oinput, &oensureAscii, &idoublePrecision))
{
return NULL;
}
if (oensureAscii != NULL && !PyObject_IsTrue(oensureAscii))
{
encoder.forceASCII = 0;
}
encoder.doublePrecision = idoublePrecision;
PRINTMARK();
ret = JSON_EncodeObject (oinput, &encoder, buffer, sizeof (buffer));
PRINTMARK();

3315
python/sample.json Normal file

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
#define UJSON_VERSION "1.16"
#define UJSON_VERSION "1.17"

@ -66,7 +66,7 @@ tree doesn't have cyclic references.
// Max recursion depth, default for encoder
#ifndef JSON_MAX_RECURSION_DEPTH
#define JSON_MAX_RECURSION_DEPTH 256
#define JSON_MAX_RECURSION_DEPTH 1024
#endif
/*