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.

     1 <!DOCTYPE html>
     2 <head>
     3 <!--
     4  Copyright (C) 2007 Apple Inc.  All rights reserved.
     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.
    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 -->
    28 <title>SunSpider access-nbody</title>
    30 </head>
    32 <body>
    33 <h3>access-nbody</h3>
    34 <div id="console">
    35 </div>
    37 <script>
    39 var _sunSpiderStartDate = new Date();
    41 /* The Great Computer Language Shootout
    42    http://shootout.alioth.debian.org/
    43    contributed by Isaac Gouy */
    45 var PI = 3.141592653589793;
    46 var SOLAR_MASS = 4 * PI * PI;
    47 var DAYS_PER_YEAR = 365.24;
    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 }
    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 }
    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 }
    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 }
    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 }
   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 }
   114 function Sun(){
   115    return new Body(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS);
   116 }
   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 }
   135 NBodySystem.prototype.advance = function(dt){
   136    var dx, dy, dz, distance, mag;
   137    var size = this.bodies.length;
   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;
   147          distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
   148          mag = dt / (distance * distance * distance);
   150          bodyi.vx -= dx * bodyj.mass * mag;
   151          bodyi.vy -= dy * bodyj.mass * mag;
   152          bodyi.vz -= dz * bodyj.mass * mag;
   154          bodyj.vx += dx * bodyi.mass * mag;
   155          bodyj.vy += dy * bodyi.mass * mag;
   156          bodyj.vz += dz * bodyi.mass * mag;
   157       }
   158    }
   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 }
   168 NBodySystem.prototype.energy = function(){
   169    var dx, dy, dz, distance;
   170    var e = 0.0;
   171    var size = this.bodies.length;
   173    for (var i=0; i<size; i++) {
   174       var bodyi = this.bodies[i];
   176       e += 0.5 * bodyi.mass *
   177          ( bodyi.vx * bodyi.vx
   178          + bodyi.vy * bodyi.vy
   179          + bodyi.vz * bodyi.vz );
   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;
   187          distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
   188          e -= (bodyi.mass * bodyj.mass) / distance;
   189       }
   190    }
   191    return e;
   192 }
   194 var ret;
   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;
   203         ret = bodies.energy();
   204         for (var i=0; i<max; i++){
   205             bodies.advance(0.01);
   206         }
   207         ret = bodies.energy();
   208     })();
   209 }
   212 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;
   214 document.getElementById("console").innerHTML = _sunSpiderInterval;
   215 </script>
   218 </body>
   219 </html>

mercurial