aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/postamble.js16
-rw-r--r--src/preamble.js5
-rw-r--r--src/settings.js3
3 files changed, 22 insertions, 2 deletions
diff --git a/src/postamble.js b/src/postamble.js
index 5f541733..00205abc 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -17,18 +17,30 @@ Module.callMain = function callMain(args) {
argv.push(0);
argv = allocate(argv, 'i32', ALLOC_STATIC);
+#if BENCHMARK
+ var start = Date.now();
+#endif
+
+ var ret;
+
#if CATCH_EXIT_CODE
var initialStackTop = STACKTOP;
try {
- return Module['_main'](argc, argv, 0);
+ ret = Module['_main'](argc, argv, 0);
}
catch(e) { if (e.name == "ExitStatus") return e.status; throw e; }
finally {
STACKTOP = initialStackTop;
}
#else
- return Module['_main'](argc, argv, 0);
+ ret = Module['_main'](argc, argv, 0);
#endif
+
+#if BENCHMARK
+ Module.realPrint('main() took ' + (Date.now() - start) + ' milliseconds');
+#endif
+
+ return ret;
}
{{GLOBAL_VARS}}
diff --git a/src/preamble.js b/src/preamble.js
index 75cae5c4..8a68736e 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -6,6 +6,11 @@
{{RUNTIME}}
+#if BENCHMARK
+Module.realPrint = Module.print;
+Module.print = Module.printErr = function(){};
+#endif
+
#if SAFE_HEAP
//========================================
// Debugging tools - Heap
diff --git a/src/settings.js b/src/settings.js
index ccf2a25b..6ffa8c33 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -317,6 +317,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 BENCHMARK = 0; // If 1, will just time how long main() takes to execute, and not
+ // print out anything at all whatsover. This is useful for benchmarking.
+
var ASM_JS = 0; // If 1, generate code in asm.js format. XXX This is highly experimental,
// and will not work on most codebases yet. It is NOT recommended that you
// try this yet.