Neo Universal Binary JSON – 2

Here are some details/benchmarks.

1. A typical JSON payload

data := ZnConstants httpStatusCodes associations
collect: [ :each | { #code->each key. #reason->each value } asDictionary ].

[ NeoUBJSONWriter toByteArray: data ] bench. “‘11108.114 per second'”

bytes := NeoUBJSONWriter toByteArray: data.

bytes size. “2290”

[ NeoUBJSONReader fromByteArray: bytes ] bench. “‘4412.670 per second'”

[ NeoJSONWriter toString: data ] bench. “‘11542.783 per second'”

json := NeoJSONWriter toString: data.

json size. “2358”

[ NeoJSONReader fromString: json ] bench. “‘4814.711 per second'”

2. A 1K integer array

data := (1 to: 1024) asArray.

[ NeoUBJSONWriter toByteArray: data ] bench. “‘6945.444 per second'”

bytes := NeoUBJSONWriter toByteArray: data.

bytes size. “2822”

[ NeoUBJSONReader fromByteArray: bytes ] bench. “‘3280.632 per second'”

[ NeoJSONWriter toString: data ] bench. “‘4523.095 per second'”

json := NeoJSONWriter toString: data.

json size. “4014”

[ NeoJSONReader fromString: json ] bench. “‘1253.749 per second'”

3. A 1K byte array

data := ByteArray new: 1024 streamContents: [ :out |
1024 timesRepeat: [ out nextPut: 256 atRandom – 1 ] ].

[ NeoUBJSONWriter toByteArray: data ] bench. “‘538493.501 per second'”

bytes := NeoUBJSONWriter toByteArray: data.

bytes size. “1031”

[ NeoUBJSONReader fromByteArray: bytes ] bench. “‘216269.200 per second'”

[ NeoJSONWriter toString: data ] bench. “‘4579.084 per second'”

json := NeoJSONWriter toString: data.

json size. “3686”

[ NeoJSONReader fromString: json ] bench. “‘1297.362 per second'”

Right now, only ByteArray got a highly optimised implementation. In the future, FloatArray and IntegerArray could receive the same treatment.

Sven

PS:

Note that UBJSON is not the same as BSON, nor CBOR, nor MessagePack, which all exist in the same space.

%d bloggers like this: