~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/build/pgo/js-input/access-nbody.html

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html>
 
2
<head>
 
3
<!--
 
4
 Copyright (C) 2007 Apple Inc.  All rights reserved.
 
5
 
 
6
 Redistribution and use in source and binary forms, with or without
 
7
 modification, are permitted provided that the following conditions
 
8
 are met:
 
9
 1. Redistributions of source code must retain the above copyright
 
10
    notice, this list of conditions and the following disclaimer.
 
11
 2. Redistributions in binary form must reproduce the above copyright
 
12
    notice, this list of conditions and the following disclaimer in the
 
13
    documentation and/or other materials provided with the distribution.
 
14
 
 
15
 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 
16
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
17
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
18
 PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 
19
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
20
 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
21
 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
22
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
23
 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
24
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
25
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
26
-->
 
27
 
 
28
<title>SunSpider access-nbody</title>
 
29
 
 
30
</head>
 
31
 
 
32
<body>
 
33
<h3>access-nbody</h3>
 
34
<div id="console">
 
35
</div>
 
36
 
 
37
<script>
 
38
 
 
39
var _sunSpiderStartDate = new Date();
 
40
 
 
41
/* The Great Computer Language Shootout
 
42
   http://shootout.alioth.debian.org/
 
43
   contributed by Isaac Gouy */
 
44
 
 
45
var PI = 3.141592653589793;
 
46
var SOLAR_MASS = 4 * PI * PI;
 
47
var DAYS_PER_YEAR = 365.24;
 
48
 
 
49
function Body(x,y,z,vx,vy,vz,mass){
 
50
   this.x = x;
 
51
   this.y = y;
 
52
   this.z = z;
 
53
   this.vx = vx;
 
54
   this.vy = vy;
 
55
   this.vz = vz;
 
56
   this.mass = mass;
 
57
}
 
58
 
 
59
Body.prototype.offsetMomentum = function(px,py,pz) {
 
60
   this.vx = -px / SOLAR_MASS;
 
61
   this.vy = -py / SOLAR_MASS;
 
62
   this.vz = -pz / SOLAR_MASS;
 
63
   return this;
 
64
}
 
65
 
 
66
function Jupiter(){
 
67
   return new Body(
 
68
      4.84143144246472090e+00,
 
69
      -1.16032004402742839e+00,
 
70
      -1.03622044471123109e-01,
 
71
      1.66007664274403694e-03 * DAYS_PER_YEAR,
 
72
      7.69901118419740425e-03 * DAYS_PER_YEAR,
 
73
      -6.90460016972063023e-05 * DAYS_PER_YEAR,
 
74
      9.54791938424326609e-04 * SOLAR_MASS
 
75
   );
 
76
}
 
77
 
 
78
function Saturn(){
 
79
   return new Body(
 
80
      8.34336671824457987e+00,
 
81
      4.12479856412430479e+00,
 
82
      -4.03523417114321381e-01,
 
83
      -2.76742510726862411e-03 * DAYS_PER_YEAR,
 
84
      4.99852801234917238e-03 * DAYS_PER_YEAR,
 
85
      2.30417297573763929e-05 * DAYS_PER_YEAR,
 
86
      2.85885980666130812e-04 * SOLAR_MASS
 
87
   );
 
88
}
 
89
 
 
90
function Uranus(){
 
91
   return new Body(
 
92
      1.28943695621391310e+01,
 
93
      -1.51111514016986312e+01,
 
94
      -2.23307578892655734e-01,
 
95
      2.96460137564761618e-03 * DAYS_PER_YEAR,
 
96
      2.37847173959480950e-03 * DAYS_PER_YEAR,
 
97
      -2.96589568540237556e-05 * DAYS_PER_YEAR,
 
98
      4.36624404335156298e-05 * SOLAR_MASS
 
99
   );
 
100
}
 
101
 
 
102
function Neptune(){
 
103
   return new Body(
 
104
      1.53796971148509165e+01,
 
105
      -2.59193146099879641e+01,
 
106
      1.79258772950371181e-01,
 
107
      2.68067772490389322e-03 * DAYS_PER_YEAR,
 
108
      1.62824170038242295e-03 * DAYS_PER_YEAR,
 
109
      -9.51592254519715870e-05 * DAYS_PER_YEAR,
 
110
      5.15138902046611451e-05 * SOLAR_MASS
 
111
   );
 
112
}
 
113
 
 
114
function Sun(){
 
115
   return new Body(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS);
 
116
}
 
117
 
 
118
 
 
119
function NBodySystem(bodies){
 
120
   this.bodies = bodies;
 
121
   var px = 0.0;
 
122
   var py = 0.0;
 
123
   var pz = 0.0;
 
124
   var size = this.bodies.length;
 
125
   for (var i=0; i<size; i++){
 
126
      var b = this.bodies[i];
 
127
      var m = b.mass;
 
128
      px += b.vx * m;
 
129
      py += b.vy * m;
 
130
      pz += b.vz * m;
 
131
   }
 
132
   this.bodies[0].offsetMomentum(px,py,pz);
 
133
}
 
134
 
 
135
NBodySystem.prototype.advance = function(dt){
 
136
   var dx, dy, dz, distance, mag;
 
137
   var size = this.bodies.length;
 
138
 
 
139
   for (var i=0; i<size; i++) {
 
140
      var bodyi = this.bodies[i];
 
141
      for (var j=i+1; j<size; j++) {
 
142
         var bodyj = this.bodies[j];
 
143
         dx = bodyi.x - bodyj.x;
 
144
         dy = bodyi.y - bodyj.y;
 
145
         dz = bodyi.z - bodyj.z;
 
146
 
 
147
         distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
 
148
         mag = dt / (distance * distance * distance);
 
149
 
 
150
         bodyi.vx -= dx * bodyj.mass * mag;
 
151
         bodyi.vy -= dy * bodyj.mass * mag;
 
152
         bodyi.vz -= dz * bodyj.mass * mag;
 
153
 
 
154
         bodyj.vx += dx * bodyi.mass * mag;
 
155
         bodyj.vy += dy * bodyi.mass * mag;
 
156
         bodyj.vz += dz * bodyi.mass * mag;
 
157
      }
 
158
   }
 
159
 
 
160
   for (var i=0; i<size; i++) {
 
161
      var body = this.bodies[i];
 
162
      body.x += dt * body.vx;
 
163
      body.y += dt * body.vy;
 
164
      body.z += dt * body.vz;
 
165
   }
 
166
}
 
167
 
 
168
NBodySystem.prototype.energy = function(){
 
169
   var dx, dy, dz, distance;
 
170
   var e = 0.0;
 
171
   var size = this.bodies.length;
 
172
 
 
173
   for (var i=0; i<size; i++) {
 
174
      var bodyi = this.bodies[i];
 
175
 
 
176
      e += 0.5 * bodyi.mass *
 
177
         ( bodyi.vx * bodyi.vx
 
178
         + bodyi.vy * bodyi.vy
 
179
         + bodyi.vz * bodyi.vz );
 
180
 
 
181
      for (var j=i+1; j<size; j++) {
 
182
         var bodyj = this.bodies[j];
 
183
         dx = bodyi.x - bodyj.x;
 
184
         dy = bodyi.y - bodyj.y;
 
185
         dz = bodyi.z - bodyj.z;
 
186
 
 
187
         distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
 
188
         e -= (bodyi.mass * bodyj.mass) / distance;
 
189
      }
 
190
   }
 
191
   return e;
 
192
}
 
193
 
 
194
var ret;
 
195
 
 
196
for ( var n = 3; n <= 24; n *= 2 ) {
 
197
    (function(){
 
198
        var bodies = new NBodySystem( Array(
 
199
           Sun(),Jupiter(),Saturn(),Uranus(),Neptune()
 
200
        ));
 
201
        var max = n * 100;
 
202
        
 
203
        ret = bodies.energy();
 
204
        for (var i=0; i<max; i++){
 
205
            bodies.advance(0.01);
 
206
        }
 
207
        ret = bodies.energy();
 
208
    })();
 
209
}
 
210
 
 
211
 
 
212
var _sunSpiderInterval = new Date() - _sunSpiderStartDate;
 
213
 
 
214
document.getElementById("console").innerHTML = _sunSpiderInterval;
 
215
</script>
 
216
 
 
217
 
 
218
</body>
 
219
</html>