JSON2 vs JSON3 Strinfigy

JavaScript performance comparison

Revision 3 of this test case created by Helder Magalhães

Preparation code

<!-- Native JSON -->
<script>
  this._NativeJSON = this.JSON;
  this.JSON = null;
</script>
<!-- JSON 3 v3.2.2 -->
<script>
  // Disable the native JSON implementation.
  this.JSON = null;
</script>
<script src="http://bestiejs.github.com/json3/lib/json3.min.js">
</script>
<!-- JSON 2 -->
<script>
  // Set up JSON 2.
  this.JSON3 = this.JSON;
  this.JSON = null;
</script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js">
</script>
<script>
  this.JSON2 = this.JSON;
  this.JSON = null;
</script>
<script>
function toStrSansLibs(b){var a="",c;if(null==b)a="null";else if(b instanceof Object)if(b instanceof Array){a="[";for(c=0;c<b.length;c++)0<c&&(a+=","),a+=toStrSansLibs(b[c]);a+="]"}else{for(c in b)b.hasOwnProperty(c)&&(a=""===a?"{":a+",",a+=c+":"+toStrSansLibs(b[c]));a+="}"}else a="string"===typeof b?'"'+b+'"':"undefined"===typeof b?"undefined":b.toString();return a};
</script>
<script>
Benchmark.prototype.setup = function() {
    var test_json = {
      "kitcambridge": "Kit",
      "contributors": {
        "jdalton": "John-David",
        "mathias": "Mathias"
      },
      "list": [1, 2, 3],
      "number": 5,
      "date": "2012-04-25T14:08:36.879Z",
      "boolean": true,
      "nil": null
    };
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
JSON2.stringify
JSON2.stringify(test_json)
pending…
JSON3.stringify
JSON3.stringify(test_json);
pending…
No libs, artisanal js
toStrSansLibs(test_json);
pending…
Native JSON
// use variable workaround due to inclusion of JSON2/3 libraries
_NativeJSON.stringify(test_json);
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