vec3 foreach
JavaScript performance comparison
Info
Testing performance of a "foreach" concept for glMatrix 2.0
Preparation code
<script>
Benchmark.prototype.setup = function() {
var vec3 = {};
vec3.add = function(out, a, b) {
out[0] = a[0] + b[0];
out[1] = a[1] + b[1];
out[2] = a[2] + b[2];
return out;
};
vec3.forEach = (function() {
var vec = new Float32Array(3);
return function(a, stride, offset, count, fn, arg) {
var i, l;
if(!stride) {
stride = 3;
}
if(count) {
l = Math.min(count * stride, a.length - offset);
} else {
l = a.length - offset;
}
for(i = offset; i < l; i += stride) {
vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2];
fn(vec, vec, arg);
a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2];
}
return a;
};
})();
var vecs = new Float32Array(3000);
var v1 = new Float32Array([0, 0, 0]);
var v2 = new Float32Array([5, 5, 5]);
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Manual Loop |
|
pending… |
Optimized Loop |
|
pending… |
ForEach loop |
|
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 Brandon Jones
- Revision 2: published
- Revision 3: published
- Revision 4: published
0 comments