build/pgo/js-input/access-nbody.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial