JSON.minify

JavaScript performance comparison

Revision 3 of this test case created by tomByrer

Info

Compares @getify's regular expression-based JSON.minify() implementation with my character-based parser, Finite State Machine.

v3: + fkei's version, jsDelivr where possible.

Preparation code

<script src="https://rawgit.com/kitcambridge/JSON.minify/master/minify-sans-regexp.js"></script>
<script>var KM = JSON.minify;</script>
<script src="https://cdn.jsdelivr.net/json-minify/0.1/minify.json.js"></script>
<script>var GM = JSON.minify;</script>
<script src="https://rawgit.com/danielyule/JSON.minify/master/minify.json.js"></script>
<script>var DM = JSON.minify;</script>
<script src="https://rawgit.com/fkei/JSON.minify/master/minify.json.js"></script>
<script>var KF = JSON.minify;</script>
<!-- Borrowed from @getify's `test.minify.html` -->
<textarea id="orig_json1" cols="50" rows="12">
  // this is a JSON file with comments { "foo": "bar", // this is cool "bar": [ "baz",
  "bum", "zam" ], /* the rest of this document is just fluff in case you are interested.
  */ "something": 10, "else": 20 } /* NOTE: You can easily strip the whitespace and
  comments from such a file with the JSON.minify() project hosted here on github at
  http://github.com/getify/JSON.minify */
</textarea>
<textarea id="orig_json2" cols="50" rows="12">
  {"/*":"*/","//":"",/*"//"*/"/*/":// "//"}
</textarea>
<textarea id="orig_json3" cols="50" rows="12">
  /* this is a multi line comment */{ "foo" : "bar/*"// something , "b\"az":/* something
  else */"blah" }
</textarea>
<textarea id="orig_json4" cols="50" rows="12">
  {"foo": "ba\"r//", "bar\\": "b\\\"a/*z", "baz\\\\": /* yay */ "fo\\\\\"*/o" }
</textarea>
<script>
Benchmark.prototype.setup = function() {
        var kitMinify = KM,
        getiMinify = GM,
        dyMinify = DM,
        kfMinify = KF,
        first = document.getElementById("orig_json1").value,
        second = document.getElementById("orig_json2").value,
        third = document.getElementById("orig_json3").value,
        fourth = document.getElementById("orig_json4").value;
};
</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
RegEx
getiMinify (first);
getiMinify (second);
//getiMinify (third);
getiMinify (fourth);
pending…
Character-Based
kitMinify(first);
kitMinify(second);
//kitMinify(third);
kitMinify(fourth);
pending…
Finite State Machine
dyMinify(first);
dyMinify(second);
//dyMinify(third);
dyMinify(fourth);
pending…
fkei
kfMinify(first);
kfMinify(second);
//kfMinify(third);
kfMinify(fourth);
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