JSON.stringify VS BJSON.serialize

JavaScript performance comparison

Test case created by Jonas Finnemann Jensen

Preparation code

<script src="http://jonasfj.github.com/BJSON.coffee/src/encoding.js"></script>
<script src="http://jonasfj.github.com/BJSON.coffee/bin/BJSON.js"></script>
<script src="http://jonasfj.github.com/BJSON.coffee/bin/test-data.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  allTests = [
     "bitly-burstphrases.json",
     "bitly-clickrate.json",
     "bitly-hotphrases.json",
     "bitly-linkinfo.json",
     "flickr-hottags.json",
     "twitter-search.json",
     "yahoo-weather.json",
     "youtube-comments.json",
     "youtube-featured.json",
     "youtube-search.json"
  ]

};
</script>

Preparation code output

<script src="http://jonasfj.github.com/BJSON.coffee/bin/BJSON.js"></script> <script src="http://jonasfj.github.com/BJSON.coffee/bin/test-data.js"></script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
JSON.stringify(data)
for(var i = 0; i < allTests.length; i++){
 var test = allTests[i];
 var data = testData[test];
 JSON.stringify(data);
}
pending…
BJSON.serialize(data)
for(var i = 0; i < allTests.length; i++){
 var test = allTests[i];
 var data = testData[test];
 BJSON.serialize(data);
}
pending…
TextEncoder().encode(JSON.stringify(data))
for(var i = 0; i < allTests.length; i++){
 var test = allTests[i];
 var data = testData[test];
 TextEncoder('utf-8').encode(JSON.stringify(data));
}
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.

1 Comment

Jonas Finnemann Jensen (revision owner) commented :

Judging from these results, it seems BJSON is very slow and that it might pay off to optimize the serialization... With a better dynamically sized binary buffer it might be possible to get a better amortized complexity (counted in the number of reallocations).