Batching Line Drawing Calls (v27)

Revision 27 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');
  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 = 0; i < 1000; ++i) {
  context.beginPath();
  context.moveTo(100 + i, 100 + i);
  context.lineTo(540 + i, 380 + i);
  context.stroke();
}
ready
one polyline
context.beginPath();
for (var i = 0; i < 1000; ++i) {
  context.moveTo(100 + i, 100 + i);
  context.lineTo(540 + i, 380 + i);
}
context.stroke();
ready
five polylines
for (var j = 0; j < 5; ++j) {
  context.beginPath();
  for (var i = 0; i < 200; ++i) {
    context.moveTo(100 + i + 200 * j, 100 + i + 200 * j);
    context.lineTo(540 + i + 200 * j, 380 + i + 200 * j);
  }
  context.stroke();
}
ready

Revisions

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