50 points single stroke vs multiple (v43)

Revision 43 of this benchmark created on


Description

Compares drawing a simple shape out of multiple lines compared to one polyline.

Preparation HTML

<canvas id="c" width="640" height="480">
</canvas>
<script>
  var canvas = document.getElementById('c');
  var context = canvas.getContext('2d');
  var points = [];
  var generateRandomPoints = function(points, amount) {
      for (var i = amount - 1; i > 0; i--) {
        var x = Math.floor(Math.random() * 100);
        var y = Math.floor(Math.random() * 100);
        points[i] = {
          x: x,
          y: y
        };
      }
      };
  generateRandomPoints(points, 500); 
  context.strokeStyle = 'black';
</script>

Setup

context.clearRect(0, 0, canvas.width, canvas.height);

Test runner

Ready to run.

Testing in
TestOps/sec
multiple lines
for (var i = points.length - 1; i > 1; i--) {
  var p = points[i];
  var p1 = points[i - 1];
  context.beginPath();
  context.moveTo(p.x, p.y);
  context.lineTo(p1.x, p1.y);
  context.stroke();
}
ready
one polyline
context.beginPath();
for (var i = points.length - 1; i > 1; i--) {
  var p = points[i];
  var p1 = points[i - 1];
  context.moveTo(p.x, p.y);
  context.lineTo(p1.x, p1.y);
}
context.stroke();
ready

Revisions

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