Commit 9ae680d3 authored by miloyip@gmail.com's avatar miloyip@gmail.com

Added ultrajson to perftest, only tested parsing to dummy handler.

git-svn-id: https://rapidjson.googlecode.com/svn/trunk@28 c5894555-1306-4e8d-425f-1f6f381ee07c
parent 08d25ad1
#ifndef PERFTEST_H_ #ifndef PERFTEST_H_
#define PERFTEST_H_ #define PERFTEST_H_
#define TEST_RAPIDJSON 0 #define TEST_RAPIDJSON 1
#define TEST_JSONCPP 0 #define TEST_JSONCPP 1
#define TEST_YAJL 0 #define TEST_YAJL 1
#define TEST_ULTRAJSON 1
#define TEST_PLATFORM 1 #define TEST_PLATFORM 1
#if TEST_RAPIDJSON #if TEST_RAPIDJSON
//#define RAPIDJSON_SSE2 //#define RAPIDJSON_SSE2
//#define RAPIDJSON_SSE42 //#define RAPIDJSON_SSE42
......
...@@ -160,9 +160,10 @@ TEST_F(RapidJson, DocumentAccept) { ...@@ -160,9 +160,10 @@ TEST_F(RapidJson, DocumentAccept) {
} }
struct NullStream { struct NullStream {
NullStream() : length_(0) {} NullStream() /*: length_(0)*/ {}
void Put(char c) { ++length_; } void Put(char c) { /*++length_;*/ }
size_t length_; void Flush() {}
//size_t length_;
}; };
TEST_F(RapidJson, Writer_NullStream) { TEST_F(RapidJson, Writer_NullStream) {
......
UltraJSON is a fast and extendable JSON encoder and decoder written in pure C
Python bindings are available as the module ujson (through easy_install / pypi):
http://pypi.python.org/pypi/ujson/
Installation instructions:
1. Build and install ujson Python extension (requires root)
Go to <root>/python
Type: python setup.py build install
2. Run tests (as needed)
Type: python tests.py
Same instructions applies for Windows except that step 1) isn't necessary since
a prebuilt static library is included.
Preliminary benchmarks:
64-bit benchmarks Linux
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
OS Version: Ubuntu 10.10
System Type: x64-based PC
Processor: Intel(R) Core(TM) i5-2300 CPU @ 2.80GHz
Total Physical Memory: 4096 MB
Array with 256 utf-8 strings:
ujson encode : 2714.66499 calls/sec
simplejson encode : 1542.63718 calls/sec
cjson encode : 132.23604 calls/sec
ujson decode : 2079.17287 calls/sec
cjson decode : 992.21602 calls/sec
simplejson decode : 278.92061 calls/sec
Medium complex object:
ujson encode : 17849.80356 calls/sec
simplejson encode : 3524.32372 calls/sec
cjson encode : 2967.34656 calls/sec
ujson decode : 11685.87610 calls/sec
cjson decode : 8206.67906 calls/sec
simplejson decode : 6549.99750 calls/sec
Array with 256 strings:
ujson encode : 38543.50303 calls/sec
simplejson encode : 19436.45772 calls/sec
cjson encode : 12392.55614 calls/sec
ujson decode : 27207.33157 calls/sec
cjson decode : 30237.60827 calls/sec
simplejson decode : 25271.93073 calls/sec
Array with 256 doubles:
ujson encode : 6027.45931 calls/sec
simplejson encode : 2915.54871 calls/sec
cjson encode : 3546.88804 calls/sec
ujson decode : 28045.13375 calls/sec
cjson decode : 15066.73209 calls/sec
simplejson decode : 15604.98222 calls/sec
Array with 256 True values:
ujson encode : 187342.39634 calls/sec
simplejson encode : 48972.93887 calls/sec
cjson encode : 67274.93082 calls/sec
ujson decode : 158103.79663 calls/sec
cjson decode : 83237.88990 calls/sec
simplejson decode : 115645.98241 calls/sec
Array with 256 dict{string, int} pairs:
ujson encode : 25301.85690 calls/sec
simplejson encode : 5734.29472 calls/sec
cjson encode : 4447.73411 calls/sec
ujson decode : 16290.72288 calls/sec
cjson decode : 12528.56060 calls/sec
simplejson decode : 10394.23358 calls/sec
Dict with 256 arrays with 256 dict{string, int} pairs:
ujson encode : 87.40865 calls/sec
simplejson encode : 17.07889 calls/sec
cjson encode : 17.25164 calls/sec
ujson decode : 45.94026 calls/sec
cjson decode : 34.60225 calls/sec
simplejson decode : 26.92238 calls/sec
32-bit benchmarks Windows
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
OS Version: 6.1.7601 Service Pack 1 Build 7601
System Type: x64-based PC
Processor: Intel(R) Core(TM)2 Quad CPU Q9550 @ 2.83GHz 2.83 GHz
Total Physical Memory: 8191 MB
Array with 256 utf-8 strings:
ujson encode : 1191.98175 calls/sec
simplejson encode : 1013.98279 calls/sec
cjson encode : 1040.66063 calls/sec
ujson decode : 1215.66875 calls/sec
cjson decode : 493.30484 calls/sec
simplejson decode : 269.85512 calls/sec
Medium complex object:
ujson encode : 10307.63723 calls/sec
simplejson encode : 2534.94769 calls/sec
cjson encode : 2047.95118 calls/sec
ujson decode : 7274.10026 calls/sec
cjson decode : 3575.39307 calls/sec
simplejson decode : 3565.51252 calls/sec
Array with 256 strings:
ujson encode : 21348.25210 calls/sec
simplejson encode : 15736.74638 calls/sec
cjson encode : 6371.26334 calls/sec
ujson decode : 26050.25316 calls/sec
cjson decode : 16468.88215 calls/sec
simplejson decode : 21115.75770 calls/sec
Array with 256 doubles:
ujson encode : 26975.49110 calls/sec
simplejson encode : 2046.29746 calls/sec
cjson encode : 2133.56594 calls/sec
ujson decode : 28430.33722 calls/sec
cjson decode : 4114.36400 calls/sec
simplejson decode : 4419.08507 calls/sec
Array with 256 True values:
ujson encode : 89846.12897 calls/sec
simplejson encode : 34288.36862 calls/sec
cjson encode : 47168.35849 calls/sec
ujson decode : 99423.47549 calls/sec
cjson decode : 58795.91460 calls/sec
simplejson decode : 76296.14699 calls/sec
Array with 256 dict{string, int} pairs:
ujson encode : 14776.41614 calls/sec
simplejson encode : 3876.86634 calls/sec
cjson encode : 3050.65343 calls/sec
ujson decode : 12934.39432 calls/sec
cjson decode : 7993.04345 calls/sec
simplejson decode : 7152.09475 calls/sec
Here is the benchmark run from a 32bit CentOS 5.6 (Python 2.4) machine:
Array with 256 utf-8 strings:
ujson encode : 1453.30891 calls/sec
simplejson encode : 658.31181 calls/sec
cjson encode : 62.18416 calls/sec
ujson decode : 1016.58767 calls/sec
cjson decode : 455.28550 calls/sec
simplejson decode : 124.20439 calls/sec
Medium complex object:
ujson encode : 6010.21634 calls/sec
simplejson encode : 1418.77823 calls/sec
cjson encode : 1252.92530 calls/sec
ujson decode : 4637.52630 calls/sec
cjson decode : 3444.13604 calls/sec
simplejson decode : 2166.18641 calls/sec
Array with 256 strings:
ujson encode : 12252.28889 calls/sec
simplejson encode : 9351.67532 calls/sec
cjson encode : 7786.13697 calls/sec
ujson decode : 10951.17394 calls/sec
cjson decode : 15971.02425 calls/sec
simplejson decode : 6796.77480 calls/sec
Array with 256 doubles:
ujson encode : 16300.61218 calls/sec
simplejson encode : 1613.39428 calls/sec
cjson encode : 2035.58937 calls/sec
ujson decode : 17301.00746 calls/sec
cjson decode : 5785.33627 calls/sec
simplejson decode : 6199.49364 calls/sec
Array with 256 True values:
ujson encode : 72618.15350 calls/sec
simplejson encode : 18707.57593 calls/sec
cjson encode : 24150.26201 calls/sec
ujson decode : 53650.94162 calls/sec
cjson decode : 48069.53050 calls/sec
simplejson decode : 47098.40293 calls/sec
Array with 256 dict{string, int} pairs:
ujson encode : 8811.85922 calls/sec
simplejson encode : 2756.91262 calls/sec
cjson encode : 1758.26962 calls/sec
ujson decode : 6490.36358 calls/sec
cjson decode : 6330.77263 calls/sec
simplejson decode : 4161.97048 calls/sec
Dict with 256 arrays with 256 dict{string, int} pairs:
ujson encode : 31.08834 calls/sec
simplejson encode : 10.41434 calls/sec
cjson encode : 6.93790 calls/sec
ujson decode : 19.81373 calls/sec
cjson decode : 20.31727 calls/sec
simplejson decode : 15.05690 calls/sec
See (python/benchmark.py) for further information.
NOTE: These benchmarks are preliminary!
/*
Copyright (c) 2011, Jonas Tarnstrom and ESN Social Software AB
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by ESN Social Software AB (www.esn.me).
4. Neither the name of the ESN Social Software AB nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY ESN SOCIAL SOFTWARE AB ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ESN SOCIAL SOFTWARE AB BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Portions of code from:
MODP_ASCII - Ascii transformations (upper/lower, etc)
http://code.google.com/p/stringencoders/
Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights reserved.
*/
/*
Ultra fast JSON encoder and decoder
Developed by Jonas Tarnstrom (jonas@esn.me).
Encoder notes:
------------------
:: Cyclic references ::
Cyclic referenced objects are not detected.
Set JSONObjectEncoder.recursionMax to suitable value or make sure input object
tree doesn't have cyclic references.
*/
#ifndef __ULTRAJSON_H__
#define __ULTRAJSON_H__
#include <stdio.h>
#include <wchar.h>
//#define JSON_DECODE_NUMERIC_AS_DOUBLE
// Don't output any extra whitespaces when encoding
#define JSON_NO_EXTRA_WHITESPACE
// Max decimals to encode double floating point numbers with
#ifndef JSON_DOUBLE_MAX_DECIMALS
#define JSON_DOUBLE_MAX_DECIMALS 9
#endif
// Max recursion depth, default for encoder
#ifndef JSON_MAX_RECURSION_DEPTH
#define JSON_MAX_RECURSION_DEPTH 256
#endif
/*
Dictates and limits how much stack space for buffers UltraJSON will use before resorting to provided heap functions */
#ifndef JSON_MAX_STACK_BUFFER_SIZE
#define JSON_MAX_STACK_BUFFER_SIZE 131072
#endif
#ifdef _WIN32
typedef __int64 JSINT64;
typedef unsigned __int64 JSUINT64;
typedef unsigned __int32 uint32_t;
typedef __int32 JSINT32;
typedef uint32_t JSUINT32;
typedef unsigned __int8 JSUINT8;
typedef unsigned __int16 JSUTF16;
typedef unsigned __int32 JSUTF32;
typedef __int64 JSLONG;
#define EXPORTFUNCTION __declspec(dllexport)
#define FASTCALL_MSVC __fastcall
#define FASTCALL_ATTR
#define INLINE_PREFIX __inline
#else
#include <sys/types.h>
typedef int64_t JSINT64;
typedef u_int64_t JSUINT64;
typedef int32_t JSINT32;
typedef u_int32_t JSUINT32;
#define FASTCALL_MSVC
#define FASTCALL_ATTR __attribute__((fastcall))
#define INLINE_PREFIX inline
typedef u_int32_t uint32_t;
typedef u_int8_t JSUINT8;
typedef u_int16_t JSUTF16;
typedef u_int32_t JSUTF32;
typedef int64_t JSLONG;
#define EXPORTFUNCTION
#endif
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__
#else
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define __BIG_ENDIAN__
#endif
#endif
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
#error "Endianess not supported"
#endif
enum JSTYPES
{
JT_NULL, // NULL
JT_TRUE, //boolean true
JT_FALSE, //boolean false
JT_INT, //(JSINT32 (signed 32-bit))
JT_LONG, //(JSINT64 (signed 64-bit))
JT_DOUBLE, //(double)
JT_UTF8, //(char 8-bit)
JT_ARRAY, // Array structure
JT_OBJECT, // Key/Value structure
JT_INVALID, // Internal, do not return nor expect
};
typedef void * JSOBJ;
typedef void * JSITER;
typedef struct __JSONTypeContext
{
int type;
void *prv[32];
} JSONTypeContext;
/*
Function pointer declarations, suitable for implementing UltraJSON */
typedef void (*JSPFN_ITERBEGIN)(JSOBJ obj, JSONTypeContext *tc);
typedef int (*JSPFN_ITERNEXT)(JSOBJ obj, JSONTypeContext *tc);
typedef void (*JSPFN_ITEREND)(JSOBJ obj, JSONTypeContext *tc);
typedef JSOBJ (*JSPFN_ITERGETVALUE)(JSOBJ obj, JSONTypeContext *tc);
typedef char *(*JSPFN_ITERGETNAME)(JSOBJ obj, JSONTypeContext *tc, size_t *outLen);
typedef void *(*JSPFN_MALLOC)(size_t size);
typedef void (*JSPFN_FREE)(void *pptr);
typedef void *(*JSPFN_REALLOC)(void *base, size_t size);
typedef struct __JSONObjectEncoder
{
void (*beginTypeContext)(JSOBJ obj, JSONTypeContext *tc);
void (*endTypeContext)(JSOBJ obj, JSONTypeContext *tc);
const char *(*getStringValue)(JSOBJ obj, JSONTypeContext *tc, size_t *_outLen);
JSINT64 (*getLongValue)(JSOBJ obj, JSONTypeContext *tc);
JSINT32 (*getIntValue)(JSOBJ obj, JSONTypeContext *tc);
double (*getDoubleValue)(JSOBJ obj, JSONTypeContext *tc);
/*
Begin iteration of an iteratable object (JS_ARRAY or JS_OBJECT)
Implementor should setup iteration state in ti->prv
*/
JSPFN_ITERBEGIN iterBegin;
/*
Retrieve next object in an iteration. Should return 0 to indicate iteration has reached end or 1 if there are more items.
Implementor is responsible for keeping state of the iteration. Use ti->prv fields for this
*/
JSPFN_ITERNEXT iterNext;
/*
Ends the iteration of an iteratable object.
Any iteration state stored in ti->prv can be freed here
*/
JSPFN_ITEREND iterEnd;
/*
Returns a reference to the value object of an iterator
The is responsible for the life-cycle of the returned string. Use iterNext/iterEnd and ti->prv to keep track of current object
*/
JSPFN_ITERGETVALUE iterGetValue;
/*
Return name of iterator.
The is responsible for the life-cycle of the returned string. Use iterNext/iterEnd and ti->prv to keep track of current object
*/
JSPFN_ITERGETNAME iterGetName;
/*
Release a value as indicated by setting ti->release = 1 in the previous getValue call.
The ti->prv array should contain the necessary context to release the value
*/
void (*releaseObject)(JSOBJ obj);
/* Library functions
Set to NULL to use STDLIB malloc,realloc,free */
JSPFN_MALLOC malloc;
JSPFN_REALLOC realloc;
JSPFN_FREE free;
/*
Configuration for max recursion, set to 0 to use default (see JSON_MAX_RECURSION_DEPTH)*/
int recursionMax;
/*
Configuration for max decimals of double floating poiunt numbers to encode (0-9) */
int doublePrecision;
/*
If true output will be ASCII with all characters above 127 encoded as \uXXXX. If false output will be UTF-8 or what ever charset strings are brought as */
int forceASCII;
/*
Set to an error message if error occured */
const char *errorMsg;
JSOBJ errorObj;
/* Buffer stuff */
char *start;
char *offset;
char *end;
int heap;
int level;
} JSONObjectEncoder;
/*
Encode an object structure into JSON.
Arguments:
obj - An anonymous type representing the object
enc - Function definitions for querying JSOBJ type
buffer - Preallocated buffer to store result in. If NULL function allocates own buffer
cbBuffer - Length of buffer (ignored if buffer is NULL)
Returns:
Encoded JSON object as a null terminated char string.
NOTE:
If the supplied buffer wasn't enough to hold the result the function will allocate a new buffer.
Life cycle of the provided buffer must still be handled by caller.
If the return value doesn't equal the specified buffer caller must release the memory using
JSONObjectEncoder.free or free() as specified when calling this function.
*/
EXPORTFUNCTION char *JSON_EncodeObject(JSOBJ obj, JSONObjectEncoder *enc, char *buffer, size_t cbBuffer);
typedef struct __JSONObjectDecoder
{
JSOBJ (*newString)(wchar_t *start, wchar_t *end);
void (*objectAddKey)(JSOBJ obj, JSOBJ name, JSOBJ value);
void (*arrayAddItem)(JSOBJ obj, JSOBJ value);
JSOBJ (*newTrue)(void);
JSOBJ (*newFalse)(void);
JSOBJ (*newNull)(void);
JSOBJ (*newObject)(void);
JSOBJ (*newArray)(void);
JSOBJ (*newInt)(JSINT32 value);
JSOBJ (*newLong)(JSINT64 value);
JSOBJ (*newDouble)(double value);
void (*releaseObject)(JSOBJ obj);
JSPFN_MALLOC malloc;
JSPFN_FREE free;
JSPFN_REALLOC realloc;
char *errorStr;
char *errorOffset;
} JSONObjectDecoder;
EXPORTFUNCTION JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer, size_t cbBuffer);
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment