JSON 3

JavaScript performance comparison

Test case created by Kit Cambridge and last updated

Info

This test benchmarks JSON 3 against other JSON implementations.

The following implementations support parsing and serializing:

The following implementations only support parsing:

Preparation code

<!-- 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>
<!-- `json-parse-state` (Crockford's state machine parser) -->
<script src="http://rawgithub.com/douglascrockford/JSON-js/master/json_parse_state.js"></script>
<script>
  // `json-parse` is exposed via the `json_parse` function as well.
  this.json_parse_state = this.json_parse;
</script>
<!-- `json-parse` (Crockford's recursive descent parser) -->
<script src="http://rawgithub.com/douglascrockford/JSON-js/master/json_parse.js"></script>
<!-- Mike Samuel's `json-sans-eval` -->
<script src="http://json-sans-eval.googlecode.com/svn/trunk/src/json_sans_eval.js"></script>
<!-- Asen Bozhilov's `evalJSON` -->
<script src="http://rawgithub.com/abozhilov/json/master/src/json.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var value = '{"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
JSON 3: parse
JSON3.parse(value);
pending…
JSON 2: parse
JSON2.parse(value);
pending…
json-parse-state
json_parse_state(value);
pending…
json-parse
json_parse(value);
pending…
json-sans-eval
jsonParse(value);
pending…
evalJSON
evalJSON(value);
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:

2 comments

Kit Cambridge (revision owner) commented :

This is an updated version of Scott Hamper's jsPerf test case; I created a new test case only so that it would have a more memorable URL. Eventually, I'd like to add benchmarks for stringify as well.

Keep in mind that, although these benchmarks disable the native JSON implementations, this is unlikely to be the case in real-world usage. Firefox's parse has been fully compliant since version 4.0 (and stringify since 5.0); Opera's since version 11.6, and Chrome's since version 11. The notable exception is Safari, which still isn't compliant as of version 5.1.5. Fortunately, JSON 3 is the third-fastest implementation in this browser—even faster than JSON 2!

Also, note that json-sans-eval is non-validating, which means that it may produce unexpected results for invalid JSON (though the trade-off is a substantial performance benefit in nearly all browsers).

My test machine is a 3.06 GHz Core i3 iMac.

Add a comment