canvas pixel loop
JavaScript performance comparison
Info
Benchmark different methods for looping a simple filter through image pixels.
Preparation code
<script>
var canvas = document.createElement('canvas');
canvas.width = 256;
canvas.height = 256;
var ctx = canvas.getContext('2d');
ctx.fillRect(0, 0, 256, 256);
var id = ctx.getImageData(0, 0, 256, 256);
var pixels = id.data;
var length = pixels.length;
var width = id.width;
var height = id.height;
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
property accesses 2d |
|
pending… |
property accesses 1d |
|
pending… |
local variables 2d |
|
pending… |
local variables 1d |
|
pending… |
local variables 1d hack one |
|
pending… |
local variables 1d hack two |
|
pending… |
local variables 1d hack three |
|
pending… |
local variables 2d cache-unfriendly |
|
pending… |
local variables 1d hack four |
|
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 by Ilmari Heikkinen
- Revision 3: published by Ilmari Heikkinen
- Revision 4: published
- Revision 5: published by Jim Hough
- Revision 6: published
- Revision 7: published
0 comments