Canvas fillStyle - cached or not? (v2)

Revision 2 of this benchmark created on


Description

Check whether fillStyle is cached in Canvas implementation so that performance doesn't degrade if called with the same value repeatedly.

Preparation HTML

<canvas id="c" width="120" height="120" style="image-rendering: -webkit-optimize-contrast;"/>
<script>
  var canvas = document.getElementById('c'),
      ctx = canvas.getContext('2d');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
fillStyle 'red'
ctx.fillStyle = 'red';
ctx.strokeStyle = 'red';
for (var i = 0; i < 100; i++) {
 ctx.strokeRect(10, 10, 100, 100);
}
ready
fillStyle 'rgba()'
ctx.fillStyle = 'red';
ctx.strokeStyle = 'red';
for (var i = 0; i < 100; i++) {
 ctx.strokeRect(10.5, 10.5, 100, 100);
}
ready

Revisions

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