From e44b9d6a9ea7fec734624ad21acd97bfc13aaaf8 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 11 Jun 2014 13:42:56 -0700 Subject: DETERMINISTIC option --- src/deterministic.js | 21 +++++++++++++++++++++ src/determinstic.js | 20 -------------------- src/jsifier.js | 3 +++ src/settings.js | 3 +++ 4 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 src/deterministic.js delete mode 100644 src/determinstic.js (limited to 'src') diff --git a/src/deterministic.js b/src/deterministic.js new file mode 100644 index 00000000..4e9508f3 --- /dev/null +++ b/src/deterministic.js @@ -0,0 +1,21 @@ + +var MAGIC = 0; +Math.random = function() { + MAGIC = Math.pow(MAGIC + 1.8912, 3) % 1; + return MAGIC; +}; +var TIME = 10000; +Date.now = function() { + return TIME++; +}; +if (typeof performance === 'object') performance.now = Date.now; + +function hashMemory(id) { + var ret = 0; + var len = Math.max(DYNAMICTOP, STATICTOP); + for (var i = 0; i < len; i++) { + ret = (ret*17 + HEAPU8[i])|0; + } + printErr(id + ':' + ret); +} + diff --git a/src/determinstic.js b/src/determinstic.js deleted file mode 100644 index 1ec0bbfe..00000000 --- a/src/determinstic.js +++ /dev/null @@ -1,20 +0,0 @@ - -var MAGIC = 0; -Math.random = function() { - MAGIC = Math.pow(MAGIC + 1.8912, 3) % 1; - return MAGIC; -}; -var TIME = 10000; -Date.now = function() { - return TIME++; -}; -performance.now = Date.now; - -function hashMemory(id) { - var ret = 0; - for (var i = 0; i < HEAPU8.length; i++) { - ret = (ret*17 + HEAPU8[i])|0; - } - print(id + ':' + ret); -} - diff --git a/src/jsifier.js b/src/jsifier.js index 791273f4..a7a53803 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1901,6 +1901,9 @@ function JSify(data, functionsOnly) { if (PROXY_TO_WORKER) { print(read('proxyWorker.js')); } + if (DETERMINISTIC) { + print(read('deterministic.js')); + } if (RUNTIME_TYPE_INFO) { Types.cleanForRuntime(); print('Runtime.typeInfo = ' + JSON.stringify(Types.types)); diff --git a/src/settings.js b/src/settings.js index a8761d90..26883051 100644 --- a/src/settings.js +++ b/src/settings.js @@ -478,6 +478,9 @@ var HEADLESS = 0; // If 1, will include shim code that tries to 'fake' a browser // very partial - it is hard to fake a whole browser! - so // keep your expectations low for this to work. +var DETERMINISTIC = 0; // If 1, we force Date.now(), Math.random, etc. to return deterministic + // results. Good for comparing builds for debugging purposes (and nothing else) + var BENCHMARK = 0; // If 1, will just time how long main() takes to execute, and not // print out anything at all whatsoever. This is useful for benchmarking. -- cgit v1.2.3-18-g5258