putImageData vs JS PNG
JavaScript performance comparison
Preparation code
<canvas></canvas>
<script src="http://www.xarg.org/download/pnglib.js"></script>
<script>
var width = 400, height = 300;
var canvas = document.getElementsByTagName('canvas')[0];
var context = canvas.getContext('2d');
canvas.width = width;
canvas.height = height;
context.fillStyle = '#ffcc00';
var rand = function(min, max) {
var r;
do {
r = Math.random();
} while (r === 1.0);
return min + parseInt(r * (max - min + 1), 10);
};
var data = [];
for (var i = 0; i < width * height; i++) {
data[i] = {
r: rand(0, 255),
g: rand(0, 255),
b: rand(0, 255),
a: rand(0, 255)
};
}
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
putImageData |
|
pending… |
JS PNG |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments