diff options
-rw-r--r-- | src/relooper/Relooper.cpp | 26 | ||||
-rw-r--r-- | src/shell.html | 43 | ||||
-rw-r--r-- | system/include/emscripten/emscripten.h | 7 | ||||
-rw-r--r-- | tests/box2d/Benchmark.cpp | 21 | ||||
-rw-r--r-- | tests/sqlite/benchmark.c | 40 | ||||
-rw-r--r-- | tools/js_optimizer.py | 6 | ||||
-rw-r--r-- | tools/shared.py | 2 |
7 files changed, 112 insertions, 33 deletions
diff --git a/src/relooper/Relooper.cpp b/src/relooper/Relooper.cpp index 204986da..14c203e0 100644 --- a/src/relooper/Relooper.cpp +++ b/src/relooper/Relooper.cpp @@ -1,3 +1,7 @@ +// We are implementing the Relooper C API, so always export from this file. +#ifndef RELOOPERDLL_EXPORTS +#define RELOOPERDLL_EXPORTS +#endif #include "Relooper.h" @@ -1269,7 +1273,7 @@ VoidIntMap __blockDebugMap__; // maps block pointers in currently running code t extern "C" { -void rl_set_output_buffer(char *buffer, int size) { +RELOOPERDLL_API void rl_set_output_buffer(char *buffer, int size) { #if DEBUG printf("#include \"Relooper.h\"\n"); printf("int main() {\n"); @@ -1279,15 +1283,15 @@ void rl_set_output_buffer(char *buffer, int size) { Relooper::SetOutputBuffer(buffer, size); } -void rl_make_output_buffer(int size) { +RELOOPERDLL_API void rl_make_output_buffer(int size) { Relooper::SetOutputBuffer((char*)malloc(size), size); } -void rl_set_asm_js_mode(int on) { +RELOOPERDLL_API void rl_set_asm_js_mode(int on) { Relooper::SetAsmJSMode(on); } -void *rl_new_block(const char *text, const char *branch_var) { +RELOOPERDLL_API void *rl_new_block(const char *text, const char *branch_var) { Block *ret = new Block(text, branch_var); #if DEBUG printf(" void *b%d = rl_new_block(\"// code %d\");\n", ret->Id, ret->Id); @@ -1297,21 +1301,21 @@ void *rl_new_block(const char *text, const char *branch_var) { return ret; } -void rl_delete_block(void *block) { +RELOOPERDLL_API void rl_delete_block(void *block) { #if DEBUG printf(" rl_delete_block(block_map[%d]);\n", ((Block*)block)->Id); #endif delete (Block*)block; } -void rl_block_add_branch_to(void *from, void *to, const char *condition, const char *code) { +RELOOPERDLL_API void rl_block_add_branch_to(void *from, void *to, const char *condition, const char *code) { #if DEBUG printf(" rl_block_add_branch_to(block_map[%d], block_map[%d], %s%s%s, %s%s%s);\n", ((Block*)from)->Id, ((Block*)to)->Id, condition ? "\"" : "", condition ? condition : "NULL", condition ? "\"" : "", code ? "\"" : "", code ? code : "NULL", code ? "\"" : ""); #endif ((Block*)from)->AddBranchTo((Block*)to, condition, code); } -void *rl_new_relooper() { +RELOOPERDLL_API void *rl_new_relooper() { #if DEBUG printf(" void *block_map[10000];\n"); printf(" void *rl = rl_new_relooper();\n"); @@ -1319,18 +1323,18 @@ void *rl_new_relooper() { return new Relooper; } -void rl_delete_relooper(void *relooper) { +RELOOPERDLL_API void rl_delete_relooper(void *relooper) { delete (Relooper*)relooper; } -void rl_relooper_add_block(void *relooper, void *block) { +RELOOPERDLL_API void rl_relooper_add_block(void *relooper, void *block) { #if DEBUG printf(" rl_relooper_add_block(rl, block_map[%d]);\n", ((Block*)block)->Id); #endif ((Relooper*)relooper)->AddBlock((Block*)block); } -void rl_relooper_calculate(void *relooper, void *entry) { +RELOOPERDLL_API void rl_relooper_calculate(void *relooper, void *entry) { #if DEBUG printf(" rl_relooper_calculate(rl, block_map[%d]);\n", ((Block*)entry)->Id); printf(" rl_relooper_render(rl);\n"); @@ -1342,7 +1346,7 @@ void rl_relooper_calculate(void *relooper, void *entry) { ((Relooper*)relooper)->Calculate((Block*)entry); } -void rl_relooper_render(void *relooper) { +RELOOPERDLL_API void rl_relooper_render(void *relooper) { ((Relooper*)relooper)->Render(); } diff --git a/src/shell.html b/src/shell.html index efb9e91d..7a3a8d08 100644 --- a/src/shell.html +++ b/src/shell.html @@ -11,10 +11,44 @@ div.emscripten_border { border: 1px solid black; } /* the canvas *must not* have any border or padding, or mouse coords will be wrong */ canvas.emscripten { border: 0px none; } + + .spinner { + height: 50px; + width: 50px; + margin: 0px auto; + -webkit-animation: rotation .8s linear infinite; + -moz-animation: rotation .8s linear infinite; + -o-animation: rotation .8s linear infinite; + animation: rotation 0.8s linear infinite; + border-left: 10px solid rgb(0,150,240); + border-right: 10px solid rgb(0,150,240); + border-bottom: 10px solid rgb(0,150,240); + border-top: 10px solid rgb(100,0,200); + border-radius: 100%; + background-color: rgb(200,100,250); + } + @-webkit-keyframes rotation { + from {-webkit-transform: rotate(0deg);} + to {-webkit-transform: rotate(360deg);} + } + @-moz-keyframes rotation { + from {-moz-transform: rotate(0deg);} + to {-moz-transform: rotate(360deg);} + } + @-o-keyframes rotation { + from {-o-transform: rotate(0deg);} + to {-o-transform: rotate(360deg);} + } + @keyframes rotation { + from {transform: rotate(0deg);} + to {transform: rotate(360deg);} + } + </style> </head> <body> <hr/> + <figure style="overflow:visible;" id="spinner"><div class="spinner"></div><center style="margin-top:0.5em"><strong>emscripten</strong></center></figure> <div class="emscripten" id="status">Downloading...</div> <div class="emscripten"> <progress value="0" max="100" id="progress" hidden=1></progress> @@ -35,7 +69,10 @@ <textarea class="emscripten" id="output" rows="8"></textarea> <hr> <script type='text/javascript'> - // connect to canvas + var statusElement = document.getElementById('status'); + var progressElement = document.getElementById('progress'); + var spinnerElement = document.getElementById('spinner'); + var Module = { preRun: [], postRun: [], @@ -68,17 +105,17 @@ var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); var now = Date.now(); if (m && now - Date.now() < 30) return; // if this is a progress update, skip it if too soon - var statusElement = document.getElementById('status'); - var progressElement = document.getElementById('progress'); if (m) { text = m[1]; progressElement.value = parseInt(m[2])*100; progressElement.max = parseInt(m[4])*100; progressElement.hidden = false; + spinnerElement.hidden = false; } else { progressElement.value = null; progressElement.max = null; progressElement.hidden = true; + if (!text) spinnerElement.hidden = true; } statusElement.innerHTML = text; }, diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h index b6e6307b..fb456d67 100644 --- a/system/include/emscripten/emscripten.h +++ b/system/include/emscripten/emscripten.h @@ -227,7 +227,14 @@ void emscripten_get_canvas_size(int *width, int *height, int *isFullscreen); * absolute time, and is only meaningful in comparison to * other calls to this function. The unit is ms. */ +#if EMSCRIPTEN double emscripten_get_now(); +#else +#include <time.h> +double emscripten_get_now() { + return (1000*clock())/(double)CLOCKS_PER_SEC; +} +#endif /* * Simple random number generation in [0, 1), maps to Math.random(). diff --git a/tests/box2d/Benchmark.cpp b/tests/box2d/Benchmark.cpp index 0db1d4be..14aa1591 100644 --- a/tests/box2d/Benchmark.cpp +++ b/tests/box2d/Benchmark.cpp @@ -25,6 +25,10 @@ typedef struct { #include <time.h> #include <math.h> +#if EMSCRIPTEN +#include <emscripten.h> +#endif + #include "Box2D/Box2D.h" using namespace std; @@ -53,6 +57,10 @@ result_t measure(clock_t *times) { } int main(int argc, char **argv) { +#if EMSCRIPTEN + emscripten_run_script("if (Module.reportStartedUp) Module.reportStartedUp()"); +#endif + int arg = argc > 1 ? argv[1][0] - '0' : 3; switch(arg) { case 0: return 0; break; @@ -64,6 +72,10 @@ int main(int argc, char **argv) { default: printf("error: %d\\n", arg); return -1; } + // do not split out warmup, do not ignore initial stalls + FRAMES += WARMUP; + WARMUP = 0; + // Define the gravity vector. b2Vec2 gravity(0.0f, -10.0f); @@ -115,12 +127,15 @@ int main(int argc, char **argv) { world.Step(1.0f/60.0f, 3, 3); } - clock_t times[FRAMES]; + clock_t times[FRAMES], min = CLOCKS_PER_SEC * 1000 * 100, max = -1; for (int32 i = 0; i < FRAMES; ++i) { clock_t start = clock(); world.Step(1.0f/60.0f, 3, 3); clock_t end = clock(); - times[i] = end - start; + clock_t curr = end - start; + times[i] = curr; + if (curr < min) min = curr; + if (curr > max) max = curr; #if DEBUG printf("%f :: ", topBody->GetPosition().y); printf("%f\n", (float32)(end - start) / CLOCKS_PER_SEC * 1000); @@ -129,7 +144,7 @@ int main(int argc, char **argv) { result_t result = measure(times); - printf("frame averages: %.3f +- %.3f\n", result.mean, result.stddev); + printf("frame averages: %.3f +- %.3f, range: %.3f to %.3f \n", result.mean, result.stddev, float(min)/CLOCKS_PER_SEC * 1000, float(max)/CLOCKS_PER_SEC * 1000); return 0; } diff --git a/tests/sqlite/benchmark.c b/tests/sqlite/benchmark.c index 802abab1..de800742 100644 --- a/tests/sqlite/benchmark.c +++ b/tests/sqlite/benchmark.c @@ -2,8 +2,13 @@ #include <stdio.h> #include <sqlite3.h> +#include <emscripten.h> + +int print = 1; + static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; + if (!print) return 0; for(i=0; i<argc; i++){ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); } @@ -44,11 +49,15 @@ int test(){ return 0; } -int main(){ +int main(int argc, char **argv){ sqlite3 *db; char *zErrMsg = 0; int rc, i; clock_t t; + int n, m; + + n = argc > 1 ? atoi(argv[1]) : 5000; + m = argc > 2 ? atoi(argv[2]) : 1; rc = sqlite3_open(":memory:", &db); if( rc ){ @@ -69,20 +78,21 @@ int main(){ #define TIME(msg) \ { \ - printf(msg " : took %d ms\n", (1000*(clock()-t))/CLOCKS_PER_SEC); \ - t = clock(); \ + int now = emscripten_get_now(); \ + printf(msg " : took %d ms\n", (int)(now - t)); \ + t = now; \ } t = clock(); - TIME("'startup'"); + TIME("'startup' - IGNORE THIS VALUE, it is an artifact"); RUN("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100));"); TIME("create table"); RUN("BEGIN;"); - // 25000 INSERTs in a transaction - for (i = 0; i < 5000; i++) { + // n*5 INSERTs in a transaction + for (i = 0; i < n; i++) { RUN("INSERT INTO t1 VALUES(1,12345,'one 1 one 1 one 1');"); RUN("INSERT INTO t1 VALUES(2,23422,'two two two two');"); RUN("INSERT INTO t1 VALUES(3,31233,'three three 33333333333 three');"); @@ -95,10 +105,13 @@ int main(){ TIME("commit"); // Counts - RUN("SELECT count(*) FROM t1;"); - RUN("SELECT count(*) FROM t1 WHERE a == 4"); - RUN("SELECT count(*) FROM t1 WHERE b > 20000 AND b < 50000;"); - RUN("SELECT count(*) FROM t1 WHERE c like '%three%';"); + for (i = 0; i < m; i++) { + print = i == 0; + RUN("SELECT count(*) FROM t1;"); + RUN("SELECT count(*) FROM t1 WHERE a == 4"); + RUN("SELECT count(*) FROM t1 WHERE b > 20000 AND b < 50000;"); + RUN("SELECT count(*) FROM t1 WHERE c like '%three%';"); + } TIME("selects"); // Index @@ -106,8 +119,11 @@ int main(){ RUN("CREATE INDEX iibb ON t1(b);"); TIME("create indexes"); - RUN("SELECT count(*) FROM t1 WHERE a == 4"); - RUN("SELECT count(*) FROM t1 WHERE b > 20000 AND b < 50000;"); + for (i = 0; i < m; i++) { + print = i == 0; + RUN("SELECT count(*) FROM t1 WHERE a == 4"); + RUN("SELECT count(*) FROM t1 WHERE b > 20000 AND b < 50000;"); + } TIME("selects with indexes"); sqlite3_close(db); diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index e030b707..9ba6643b 100644 --- a/tools/js_optimizer.py +++ b/tools/js_optimizer.py @@ -11,9 +11,9 @@ def path_from_root(*pathelems): JS_OPTIMIZER = path_from_root('tools', 'js-optimizer.js') -NUM_CHUNKS_PER_CORE = 1.5 -MIN_CHUNK_SIZE = int(os.environ.get('EMCC_JSOPT_MIN_CHUNK_SIZE') or 1024*1024) # configuring this is just for debugging purposes -MAX_CHUNK_SIZE = 20*1024*1024 +NUM_CHUNKS_PER_CORE = 3 +MIN_CHUNK_SIZE = int(os.environ.get('EMCC_JSOPT_MIN_CHUNK_SIZE') or 512*1024) # configuring this is just for debugging purposes +MAX_CHUNK_SIZE = 5*1024*1024 WINDOWS = sys.platform.startswith('win') diff --git a/tools/shared.py b/tools/shared.py index 665a6d52..f88eace0 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -345,7 +345,7 @@ def find_temp_directory(): # we re-check sanity when the settings are changed) # We also re-check sanity and clear the cache when the version changes -EMSCRIPTEN_VERSION = '1.9.4' +EMSCRIPTEN_VERSION = '1.9.5' def generate_sanity(): return EMSCRIPTEN_VERSION + '|' + get_llvm_target() + '|' + LLVM_ROOT + '|' + get_clang_version() |