min max positions

Benchmark created on


Preparation HTML

<script>
  var testPositions = [
  0, 1000, -1000, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, -1, 10, -10, -1, -10, 10, -10, 100, -10, 1235, 253, 235, 246, 26346, 2364, 744, 5368658, 45773, -689, 8, -68, ];
  
  function normalGetBoundary(positions) {
   var boundary = {
    xmin: Number.MAX_VALUE,
    ymin: Number.MAX_VALUE,
    zmin: Number.MAX_VALUE,
    xmax: Number.MIN_VALUE,
    ymax: Number.MIN_VALUE,
    zmax: Number.MIN_VALUE
   };
   var x, y, z;
   for (var i = 0, len = positions.length - 3; i < len; i += 3) {
    x = positions[i];
    y = positions[i + 1];
    z = positions[i + 2];
  
    if (x < boundary.xmin) {
     boundary.xmin = x;
    }
    if (y < boundary.ymin) {
     boundary.ymin = y;
    }
    if (z < boundary.zmin) {
     boundary.zmin = z;
    }
  
    if (x > boundary.xmax) {
     boundary.xmax = x;
    }
    if (y > boundary.ymax) {
     boundary.ymax = y;
    }
    if (z > boundary.zmax) {
     boundary.zmax = z;
    }
   }
   return boundary;
  };
  
  function fastGetBoundary(positions) {
   var boundary = {
    xmin: positions[0],
    ymin: positions[1],
    zmin: positions[2],
    xmax: positions[0],
    ymax: positions[1],
    zmax: positions[2]
   };
   var x, y, z;
   for (var i = 3, len = positions.length - 3; i < len; i += 3) {
    x = positions[i];
    y = positions[i + 1];
    z = positions[i + 2];
  
    if (x < boundary.xmin) {
     boundary.xmin = x;
    } else if (x > boundary.xmax) {
     boundary.xmax = x;
    }
    if (y < boundary.ymin) {
     boundary.ymin = y;
    } else if (y > boundary.ymax) {
     boundary.ymax = y;
    }
    if (z < boundary.zmin) {
     boundary.zmin = z;
    } else if (z > boundary.zmax) {
     boundary.zmax = z;
    }
   }
   return boundary;
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
normal
normalGetBoundary(testPositions);
ready
fast
fastGetBoundary(testPositions);
ready

Revisions

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