source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/test/benchmark/core/Vector3Length.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 1.4 KB
Line 
1THREE = {};
2
3THREE.Vector3 = function ( x, y, z ) {
4
5 this.x = x || 0;
6 this.y = y || 0;
7 this.z = z || 0;
8
9};
10
11THREE.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
35var a = [];
36
37for ( 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
44var suite = new Benchmark.Suite;
45
46suite.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
57suite.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
69suite.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
79suite.on('cycle', function(event, bench) {
80 console.log(String(event.target));
81});
82
83suite.on('complete', function() {
84 console.log('Fastest is ' + this.filter('fastest').pluck('name'));
85 console.log( "Done" );
86});
87
88suite.run(true);
Note: See TracBrowser for help on using the repository browser.