jaeojfoajioqje

JavaScript performance comparison

Test case created

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
func
function bresenham(x0, y0, x1, y1, callback) {
  var dx = Math.abs(x1 - x0);
  var dy = Math.abs(y1 - y0);
  var sx = (x0 < x1) ? 1 : -1;
  var sy = (y0 < y1) ? 1 : -1;
  var err = dx - dy;

  while (true) {
    var shouldStop = callback(x0, y0);
    if (shouldStop) {
      return true;
    }

    if ((x0 === x1) && (y0 === y1)) {
      return false;
    }
    var e2 = 2 * err;
    if (e2 > -dy) {
      err -= dy;
      x0 += sx;
    }
    if (e2 < dx) {
      err += dx;
      y0 += sy;
    }
  }
}

function collided(x, y) {
  return false;
}

function checkCollision(x, y) {
  xPrev = x;
  yPrev = y;

  return collided(x, y);
}
var hasCollided = bresenham(0, 0, 99999999, 99999999, checkCollision);
pending…
nofunc
function bresenham(x0, y0, x1, y1, callback) {
  var dx = Math.abs(x1 - x0);
  var dy = Math.abs(y1 - y0);
  var sx = (x0 < x1) ? 1 : -1;
  var sy = (y0 < y1) ? 1 : -1;
  var err = dx - dy;

  while (true) {
    xPrev = x;
    yPrev = y;

    shouldStop = collided(x, y);
    if (shouldStop) {
      return true;
    }

    if ((x0 === x1) && (y0 === y1)) {
      return false;
    }
    var e2 = 2 * err;
    if (e2 > -dy) {
      err -= dy;
      x0 += sx;
    }
    if (e2 < dx) {
      err += dx;
      y0 += sy;
    }
  }
}

function collided(x, y) {
  return false;
}


var hasCollided = bresenham(0, 0, 99999999, 99999999, checkCollision);
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