Typed arrays for pixel manipulation
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var canvas = document.createElement('canvas');
var c = canvas.getContext('2d');
var w = canvas.width = 1000;
var h = canvas.height = 1000;
var image = c.getImageData(0, 0, w, h);
for (var y = 0, i = 0; y < h; y++) {
for (var x = 0; x < w; x++, i += 4) {
image.data[i] = x & 0xFF;
image.data[i + 1] = (x ^ y) & 0xFF;
image.data[i + 2] = 0;
image.data[i + 3] = 255;
}
}
var buffer1 = Array.prototype.slice.call(image.data);
var buffer2 = Array.prototype.slice.call(image.data);
var buffer3 = Array.prototype.slice.call(image.data);
var buffer4 = new Uint8Array(image.data);
var buffer5 = new Uint8Array(image.data);
var buffer6 = new Uint8Array(image.data);
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Array |
|
pending… |
Uint8Array |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published
0 comments