1 | THREE = {};
|
---|
2 |
|
---|
3 | THREE.Vector3 = function ( x, y, z ) {
|
---|
4 |
|
---|
5 | this.x = x || 0;
|
---|
6 | this.y = y || 0;
|
---|
7 | this.z = z || 0;
|
---|
8 |
|
---|
9 | };
|
---|
10 |
|
---|
11 | THREE.Vector3.prototype = {
|
---|
12 |
|
---|
13 | constructor: THREE.Vector3,
|
---|
14 |
|
---|
15 | lengthSq: function () {
|
---|
16 |
|
---|
17 | return this.x * this.x + this.y * this.y + this.z * this.z;
|
---|
18 |
|
---|
19 | },
|
---|
20 |
|
---|
21 | length: function () {
|
---|
22 |
|
---|
23 | return Math.sqrt( this.lengthSq() );
|
---|
24 |
|
---|
25 | },
|
---|
26 |
|
---|
27 | length2: function () {
|
---|
28 |
|
---|
29 | return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
|
---|
30 |
|
---|
31 | }
|
---|
32 |
|
---|
33 | };
|
---|
34 |
|
---|
35 | var a = [];
|
---|
36 |
|
---|
37 | for ( var i = 0; i < 100000; i ++ ) {
|
---|
38 |
|
---|
39 | a[ i ] = new THREE.Vector3( i * 0.01, i * 2, i * -1.3 );
|
---|
40 |
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | var suite = new Benchmark.Suite;
|
---|
45 |
|
---|
46 | suite.add('NoCallTest', function() {
|
---|
47 |
|
---|
48 | var result = 0;
|
---|
49 |
|
---|
50 | for ( var i = 0; i < 100000; i ++ ) {
|
---|
51 | var v = a[i];
|
---|
52 | result += Math.sqrt( v.x * v.x + v.y * v.y + v.z * v.z );
|
---|
53 | }
|
---|
54 |
|
---|
55 | });
|
---|
56 |
|
---|
57 | suite.add('InlineCallTest', function() {
|
---|
58 |
|
---|
59 | var result = 0;
|
---|
60 |
|
---|
61 | for ( var i = 0; i < 100000; i ++ ) {
|
---|
62 |
|
---|
63 | result += a[ i ].length2();
|
---|
64 |
|
---|
65 | }
|
---|
66 |
|
---|
67 | });
|
---|
68 |
|
---|
69 | suite.add('FunctionCallTest', function() {
|
---|
70 | var result = 0;
|
---|
71 |
|
---|
72 | for ( var i = 0; i < 100000; i ++ ) {
|
---|
73 |
|
---|
74 | result += a[ i ].length();
|
---|
75 |
|
---|
76 | }
|
---|
77 | });
|
---|
78 |
|
---|
79 | suite.on('cycle', function(event, bench) {
|
---|
80 | console.log(String(event.target));
|
---|
81 | });
|
---|
82 |
|
---|
83 | suite.on('complete', function() {
|
---|
84 | console.log('Fastest is ' + this.filter('fastest').pluck('name'));
|
---|
85 | console.log( "Done" );
|
---|
86 | });
|
---|
87 |
|
---|
88 | suite.run(true); |
---|