new Vec3 vs duck
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
function ThisVec3(x, y, z){
this.x = x;
this.y = y;
this.z = z;
}
function ObjVec3(x, y, z){
return {
x: x,
y: y,
z: z
}
}
function ProtoVec3(x, y, z){
this.x = x;
this.y = y;
this.z = z;
}
ProtoVec3.prototype.add = function( vec ){
this.x += vec.x;
this.y += vec.y;
this.z += vec.z;
}
var vec3add = function( dest, other ){
dest.x += other.x;
dest.y += other.y;
dest.z += other.z;
return dest;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Vec3 using 'this' |
|
pending… |
Vec3 using factory |
|
pending… |
Vec3 with prototype |
|
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 Andrew Petersen
- Revision 2: published by Pipo
0 comments