microbenchmark wards

JavaScript performance comparison

Test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
      
<script>
Benchmark.prototype.setup = function() {
  function makeStruct(names) {
    var names = names.split(' ');
    var count = names.length;
  
    function constructor() {
      for (var i = 0; i < count; i++) {
        this[names[i]] = arguments[i];
      }
    }
    return constructor;
  }
  
  // left down: -7500, -7800 top right 7500 7400 dota1
  
  function randomCoord() {
    return Math.random() * 15000 - 7500;
  }
  
  var Box = makeStruct("x y x2 y2");
  var ward_coord = makeStruct("x y");
  
  function check(w, b) {
    if ((w.x >= b.x) && (w.x <= b.x2) && (w.y >= b.y) && (w.y <= b.y2)) return true;
    return false;
  }
  
  var boxes = new Array();
  for (var i = 0; i < 50; i++) {
    var x = randomCoord();
    var y = randomCoord();
    boxes[i] = new Box(x, y, x + Math.random() * 600, y + Math.random() * 400);
  }
  
  var mywards = new Array();
  for (var i = 0; i < 60; i++) {
    mywards[i] = new ward_coord(randomCoord(), randomCoord());
  }

};
</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
bruteforce
var myboxes = boxes.slice(0);

//test
var j;

for (var k = 0; k < 60; k++) {
  //get ward
  wards_coord = mywards[k];
  for (var m = 0; m < 50; m++) {
    if (check(wards_coord, myboxes[m] == true)) {
      j++;
    }
  }
}
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