linedrawing

Benchmark created on


Preparation HTML

<canvas width="800" height="600" id="can"></canvas>
 
<script>
  <script>
  var ctx=document.getElementByID("can").getContext("2d");
  var w =800; var h = 600;
  var lines = [];
  var i, n=30000, line;
  for (i = 0; i<n; i++){
     line=[]
     line[0]=Math.random()*(w-1)
     line[1]=Math.random()*(h-1)
     lines.push(line);
  } 
  ctx.beginPath();
  ctx.moveTo(20,20);
  
  for(i=0; i<n;i++){
     var point=lines[i];
     ctx.lineTo(point[0],point[1]);
  } 
  </script>
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
drawlines
ctx.beginPath();
ctx.moveTo(20,20);

for(i=0; i<n;i++){
   var point=lines[i];
   ctx.lineTo(point[0],point[1]);
}
ready
drawlines2
ctx.beginPath();
ctx.moveTo(20,20);

for(i=0; i<n;i++){
   ctx.lineTo(lines[i][0],lines[i][1]);
}
ready

Revisions

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