js/src/parjs-benchmarks/mandelbrot.js

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 // Adapted from
     2 //
     3 // https://github.com/RiverTrail/RiverTrail/blob/master/examples/mandelbrot/mandelbrot.js
     4 //
     5 // which in turn is adapted from a WebCL implementation available at
     6 //
     7 // http://www.ibiblio.org/e-notes/webcl/mandelbrot.html
     9 var nc = 30, maxCol = nc*3, cr,cg,cb;
    11 load(libdir + "util.js");
    13 // this is the actual mandelbrot computation, ported to JavaScript
    14 // from the WebCL / OpenCL example at
    15 // http://www.ibiblio.org/e-notes/webcl/mandelbrot.html
    16 function computeSetByRow(x, y) {
    17   var Cr = (x - 256) / scale + 0.407476;
    18   var Ci = (y - 256) / scale + 0.234204;
    19   var I = 0, R = 0, I2 = 0, R2 = 0;
    20   var n = 0;
    21   while ((R2+I2 < 2.0) && (n < 512)) {
    22     I = (R+R)*I+Ci;
    23     R = R2-I2+Cr;
    24     R2 = R*R;
    25     I2 = I*I;
    26     n++;
    27   }
    28   return n;
    29 }
    31 function computeSequentially() {
    32   result = [];
    33   for (var r = 0; r < rows; r++) {
    34     for (var c = 0; c < cols; c++) {
    35       result.push(computeSetByRow(c, r));
    36     }
    37   }
    38   return result;
    39 }
    41 function computeParallel() {
    42   return new ParallelArray([rows, cols], function(r, c) {
    43     return computeSetByRow(c, r);
    44   }).flatten();
    45 }
    47 function compare(arrs, pas) {
    48   for (var r = 0; r < rows; r++) {
    49     for (var c = 0; c < cols; c++) {
    50       assertEq(seq[c + r * cols], par.get(r, c));
    51     }
    52   }
    53 }
    55 var scale = 10000*300;
    56 var rows = 1024;
    57 var cols = 1024;
    59 // Experimentally, warmup doesn't seem to be necessary:
    60 benchmark("MANDELBROT", 1, DEFAULT_MEASURE,
    61           computeSequentially, computeParallel);

mercurial