customvsjson

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var msg = {
    type: 5,
    timeToEnd: 53,
    directions: [ '6', '4' ],
    sizes: [ 6, 6 ],
    pellets: [ 34, 21, 67, 54 ],
    score: [ 6, 5 ] 
  };
  
  var DATA_SEP = '#',
  		OBJ_SEP = ',';
  

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Custom
		var encoded = msg.type + DATA_SEP + msg.timeToEnd + DATA_SEP + msg.directions[0] + OBJ_SEP + msg.directions[1] + DATA_SEP;
		encoded += msg.sizes[0] + OBJ_SEP + msg.sizes[1] + DATA_SEP;

		 // Now add the pellets
		if (msg.pellets) {
		  var currPellet;
		  var delim;
		  for (var i = 0; i < msg.pellets.length; ++i) {
		    currPellet = msg.pellets[i];
		    delim = (i === msg.pellets.length - 1) ? '' : OBJ_SEP; // Don't add separator for the last element
		    encoded += currPellet + delim;
		  }
		}

		 // Finally add the score
		encoded += DATA_SEP + msg.score[0] + OBJ_SEP + msg.score[1];
		return encoded;
pending…
JSON
return JSON.stringify(msg);
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