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.

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

mercurial