TextPacker

JavaScript performance comparison

Revision 3 of this test case created

Info

Test different text packer changed the calls to lzstring just to see. May not be apples to apples...

Preparation code

<script language="javascript" src="//rawgithub.com/pieroxy/lz-string/master/libs/lz-string-1.3.3.js"></script>
<script language="javascript">
  window.core = {
    Module : function(name, obj) {
      var cur = window;
      name = name.split(".");
      while (name.length > 1) {
        var n = name.shift();
        if (!cur[n]) cur[n] = {};
        cur = cur[n];
      }
      cur[name[0]] = obj;
    }
  };
var glob = window;
core.Module("core.Main", {
  getGlobal : function() { return glob; }
});
var input1 = ""; // 30 characters long
var input2 = ""; // 500 characters long
var input3 = ""; // 10000 characters long
var ch = "abcdefghijklmnopqrstuvwxyz";
for (var i=0; i<30; i++) {
input1 += ch[Math.floor(Math.random()*26)];
}
for (var i=0; i<500; i++) {
input2 += ch[Math.floor(Math.random()*26)];
}
for (var i=0; i<10000; i++) {
input3 += ch[Math.floor(Math.random()*26)];
}
</script>
<script language="javascript" src="//rawgithub.com/sebastian-software/core/master/source/class/core/util/Base64.js"></script>
<script language="javascript" src="//rawgithub.com/sebastian-software/core/master/source/class/core/util/TextCompressor.js"></script>
<script>
Benchmark.prototype.teardown = function() {
    console.log("Size of compressed string: ", comp1.length + "/" + comp2.length + "/" + comp3.length);
};
</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
TextCompressor
var comp1 = core.util.TextCompressor.compress(input1);
var orig1 = core.util.TextCompressor.decompress(comp1);

var comp2 = core.util.TextCompressor.compress(input2);
var orig2 = core.util.TextCompressor.decompress(comp2);

var comp3 = core.util.TextCompressor.compress(input3);
var orig3 = core.util.TextCompressor.decompress(comp3);
pending…
LZ
var comp1 = LZString.compress(input1);
var orig1 = LZString.decompress(comp1);

var comp2 = LZString.compress(input2);
var orig2 = LZString.decompress(comp2);

var comp3 = LZString.compress(input3);
var orig3 = LZString.decompress(comp3);
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