Skip to main content
100%

Canvas Path Benchmark

✓ Published0🌍 Public
GGerHobbelt
Last edited Sep 10, 2012
Created on Aug 12, 2012

This benchmark measures the time required to draw 5,000 individual line segments on an HTML5 Canvas, comparing rendering performance across browsers. It shows how Canvas path drawing scales with increasing segment counts, with results tabulated in real time. The code uses the Canvas 2D API’s `beginPath`, `moveTo`, `lineTo`, and `stroke` methods, along with `requestAnimationFrame` to pace animation frames. It runs randomized segment generation with a subtle correction toward the canvas center, logging elapsed time per set and cumulative time in a table. The example is derived from a similar SVG benchmark, highlighting differences between Canvas and SVG rendering speeds.

AI-generated description

Canvas Path Benchmark �� <a href="http://bl.ocks.org/3331937" title="view this gist via bl.ocks.org">?</a> <a href="http://bl.ocks.org/GerHobbelt" title="view a list of all my gists at bl.ocks.org">8</a>

This example benchmarks the time taken to draw a line consisting of 5000 separate segments into an HTML5 Canvas.

It is derived from this example which performs the same Canvas benchmark but with another (non-default: 'source-over') composition mode, called 'destination-atop', which won't render identically to the SVG benchmark here.

When you want to observe the different canvas composition modes and their effect on timing, check out this benchmark; you will notice that different browsers will render different views as canvas composition mode support is not complete for many of them.

The Canvas results are faster than those measured by the equivalent SVG Path Benchmark, but mind the huge differences between the major browsers: Opera and IE9 have their SVG act together while the others are sluggish.

source: gist.github.com/gists/3331937

Similar vizzes