Files
three.js/examples/performance-test.html
T
philogbandMr.doob 2b0ea54a4c Core performance improvements through shared props
Old Vector and Matrix constructor functions would create all methods and
make assignments with each call. A lot of speed-ups can be made by using
shared properties through the prototype chain. Since methods and
initialized properties are shared among all instances they're only
created once.

Some tests can be seen at examples/performance-test.html

Some results:

    Chrome

    //6.4 times faster
    performance-test.html:25 Vector2 x 5000000: 213ms
    performance-test.html:30 Vector2Orig x 5000000: 1366ms

    //8.3 times faster
    performance-test.html:37 Vector3 x 5000000: 241ms
    performance-test.html:42 Vector3Orig x 5000000: 2015ms

    //3.8 times faster
    performance-test.html:49 Vector4 x 5000000: 278ms
    performance-test.html:54 Vector4Orig x 5000000: 1059ms

    //7.5 times faster
    performance-test.html:61 Matrix4 x 5000000: 937ms
    performance-test.html:66 Matrix4Orig x 5000000: 7004ms

    Firefox

    //6.8 times faster
    Vector2 x 50000: 45ms
    Vector2Orig x 50000: 307ms

    //11.5 times faster
    Vector3 x 50000: 48ms
    Vector3Orig x 50000: 550ms

    //3.8 times faster
    Vector4 x 50000: 61ms
    Vector4Orig x 50000: 234ms

    //9.4 times faster
    Matrix4 x 50000: 199ms
    Matrix4Orig x 50000: 1878ms

where "Orig" are old versions of the objects.

Running these tests multiple times can yeild different results due to
browser cache. However the results are always kind of similar in terms
of speedup.
2010-07-14 20:58:22 +08:00

73 lines
2.5 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Performance Tests</title>
<script type="text/javascript" src="../src/Three.js"></script>
<script type="text/javascript" src="../src/core/Vector2.js"></script>
<script type="text/javascript" src="../src/core/Vector3.js"></script>
<script type="text/javascript" src="../src/core/Vector4.js"></script>
<script type="text/javascript" src="../src/core/Matrix3.js"></script>
<script type="text/javascript" src="../src/core/Matrix4.js"></script>
<script type="text/javascript" src="../src/core/Vector2.old.js"></script>
<script type="text/javascript" src="../src/core/Vector3.old.js"></script>
<script type="text/javascript" src="../src/core/Vector4.old.js"></script>
<script type="text/javascript" src="../src/core/Matrix3.old.js"></script>
<script type="text/javascript" src="../src/core/Matrix4.old.js"></script>
<script type="text/javascript">
function initTest() {
alert("hello");
var times = 50000;
//Vector2
console.time("Vector2 x " + times);
for( var i = 0; i < times; ++i) {
var v = new THREE.Vector2();
}
console.timeEnd("Vector2 x " + times);
console.time("Vector2Orig x " + times);
for( var i = 0; i < times; ++i) {
var v = new THREE.Vector2Orig();
}
console.timeEnd("Vector2Orig x " + times);
//Vector3
console.time("Vector3 x " + times);
for( var i = 0; i < times; ++i) {
var v = new THREE.Vector3();
}
console.timeEnd("Vector3 x " + times);
console.time("Vector3Orig x " + times);
for( var i = 0; i < times; ++i) {
var v = new THREE.Vector3Orig();
}
console.timeEnd("Vector3Orig x " + times);
//Vector4
console.time("Vector4 x " + times);
for( var i = 0; i < times; ++i) {
var v = new THREE.Vector4();
}
console.timeEnd("Vector4 x " + times);
console.time("Vector4Orig x " + times);
for( var i = 0; i < times; ++i) {
var v = new THREE.Vector4Orig();
}
console.timeEnd("Vector4Orig x " + times);
//Matrix4
console.time("Matrix4 x " + times);
for( var i = 0; i < times; ++i) {
var v = new THREE.Matrix4();
}
console.timeEnd("Matrix4 x " + times);
console.time("Matrix4Orig x " + times);
for( var i = 0; i < times; ++i) {
var v = new THREE.Matrix4Orig();
}
console.timeEnd("Matrix4Orig x " + times);
}
</script>
</head>
<body onload="initTest();">
</body>
</html>