JSON vs binary parsing

JavaScript performance comparison

Test case created by Quetzacotl

Info

Check if parsing JSON is faster than parsing binary data.

Preparation code

 
<script>
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;
};
</script>

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.function;
var parameters = obj.parameters;
pending…
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];
pending…

Compare results of other browsers

Revisions

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:

0 comments

Add a comment