JSON vs binary parsing

JavaScript performance comparison

Revision 5 of this test case created


Check if parsing JSON is faster than parsing binary data.

Preparation code

Benchmark.prototype.setup = function() {
    var json = '{ "function": "moveCharacterTo", "parameters": [1234, -4567] }';
    var x = 1234;
    var y = -4567;
    var id = 5000;
    var buffer = new ArrayBuffer(6);
    var view = new Uint16Array(buffer, 0, 1);
    view[0] = id;
    view = new Int16Array(view.buffer, 2, 2);
    view[0] = x;
    view[1] = y;
    buffer = view.buffer;

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
JSON parsing
var obj = JSON.parse(json);
var function_name = obj.
var parameters = obj.parameters;
binary parse
var view = new Uint16Array(buffer);
var id_unpacked = view[0];
view = new Int16Array(buffer, 2, 2);
var x_unpacked = view[0];
var y_unpacked = view[1];

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:


Comment form temporarily disabled.

Add a comment