GameOrdersCompression

JavaScript performance comparison

Test case created by Poch

Preparation code

<div id="test1_pre">T1 PreFormatted : </div>
<div id="test1_serialized">T1 Serialized : </div>
<br><br>
<div id="test2_pre">T2 PreFormatted : </div>
<div id="test2_serialized">T2 Serialized : </div>
<br><br>
<div id="test3_pre">T3 PreFormatted : </div>
<div id="test3_serialized">T3 Serialized : </div>
<br><br>
<div id="test4_pre">T4 Preformatted : </div>
<div id="test4_serialized">T4 Serialized : </div>
<script>
Benchmark.prototype.setup = function() {
    var orders = {
        up: true,
        left: true,
        right: true,
        down: true,
        skill1: true,
        skill2: true,
        skill3: true,
        skill4: true,
        skill5: true,
        skill6: true
    };
};
</script>

Preparation code output

T1 PreFormatted :
T1 Serialized :


T2 PreFormatted :
T2 Serialized :


T3 PreFormatted :
T3 Serialized :


T4 Preformatted :
T4 Serialized :

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Conversion to binary string, then to hex string
var binaryString = "";

for (var valueName in orders) {
      if (orders[valueName] == true) binaryString += "1";
      else  binaryString += "0";
}

var serializedAsHexString = parseInt(binaryString, 2).toString(16);

if (!window.test1ResultDisplayed) {
      document.getElementById("test1_pre").innerHTML += binaryString;
      document.getElementById("test1_serialized").innerHTML += serializedAsHexString;
      window.test1ResultDisplayed = true;
}
pending…
Conversion to decimal then to hex string (down>up)
var number = 0;
var i = 1;

for (var valueName in orders) {
      var mult = 1 * i;
      i *= 10;
      if (orders[valueName] == true) number += 1 * mult;
}

var serializedAsHexString = number.toString(16);

if (!window.test2ResultDisplayed) {
      document.getElementById("test2_pre").innerHTML += number;
      document.getElementById("test2_serialized").innerHTML += serializedAsHexString;
      window.test2ResultDisplayed = true;
}
pending…
Conversion to decimal then to hex string (up>down)
var number = 0;
var i = 1000000000;

for (var valueName in orders) {
      var mult = 1 * i;
      i /= 10;
      if (orders[valueName] == true) number += 1 * mult;
}

var serializedAsHexString = number.toString(16);

if (!window.test3ResultDisplayed) {
      document.getElementById("test3_pre").innerHTML += number;
      document.getElementById("test3_serialized").innerHTML += serializedAsHexString;
      window.test3ResultDisplayed = true;
}
pending…
Conversion to "binary-decimal", then to binary, then to hex string
var number = 0;
var i = 1;

for (var valueName in orders) {
      var mult = 1 * i;
      i *= 10;
      if (orders[valueName] == true) number += 1 * mult;
}

number = parseInt(number, 2);
var serializedAsHexString = number.toString(16);

if (!window.test4ResultDisplayed) {
      document.getElementById("test4_pre").innerHTML += number;
      document.getElementById("test4_serialized").innerHTML += serializedAsHexString;
      window.test4ResultDisplayed = true;
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment