speedtest1-worker.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <!doctype html>
  2. <html lang="en-us">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
  7. <link rel="stylesheet" href="common/emscripten.css"/>
  8. <link rel="stylesheet" href="common/testing.css"/>
  9. <title>speedtest1.wasm Worker</title>
  10. </head>
  11. <body>
  12. <header id='titlebar'>speedtest1.wasm Worker</header>
  13. <div>See also: <a href='speedtest1.html'>A main-thread variant of this page.</a></div>
  14. <!-- emscripten bits -->
  15. <figure id="module-spinner">
  16. <div class="spinner"></div>
  17. <div class='center'><strong>Initializing app...</strong></div>
  18. <div class='center'>
  19. On a slow internet connection this may take a moment. If this
  20. message displays for "a long time", intialization may have
  21. failed and the JavaScript console may contain clues as to why.
  22. </div>
  23. </figure>
  24. <div class="emscripten" id="module-status">Downloading...</div>
  25. <div class="emscripten">
  26. <progress value="0" max="100" id="module-progress" hidden='1'></progress>
  27. </div><!-- /emscripten bits -->
  28. <fieldset id='ui-controls' class='hidden'>
  29. <legend>Options</legend>
  30. <div id='toolbar'>
  31. <div id='toolbar-select'>
  32. <select id='select-flags' size='10' multiple></select>
  33. <div>The following flags can be passed as URL parameters:
  34. vfs=NAME, size=N, journal=MODE, cachesize=SIZE
  35. </div>
  36. </div>
  37. <div class='toolbar-inner-vertical'>
  38. <div id='toolbar-selected-flags'></div>
  39. <div class='toolbar-inner-vertical'>
  40. <span>&rarr; <a id='link-main-thread' href='#' target='speedtest-main'
  41. title='Start speedtest1.html with the selected flags'>speedtest1</a>
  42. </span>
  43. <span class='hidden'>&rarr; <a id='link-wasmfs' href='#' target='speedtest-wasmfs'
  44. title='Start speedtest1-wasmfs.html with the selected flags'>speedtest1-wasmfs</a>
  45. </span>
  46. <span>&rarr; <a id='link-kvvfs' href='#' target='speedtest-kvvfs'
  47. title='Start kvvfs speedtest1 with the selected flags'>speedtest1-kvvfs</a>
  48. </span>
  49. </div>
  50. </div>
  51. <div class='toolbar-inner-vertical' id='toolbar-runner-controls'>
  52. <button id='btn-reset-flags'>Reset Flags</button>
  53. <button id='btn-output-clear'>Clear output</button>
  54. <button id='btn-run'>Run</button>
  55. </div>
  56. </div>
  57. </fieldset>
  58. <div>
  59. <span class='input-wrapper'>
  60. <input type='checkbox' class='disable-during-eval' id='cb-reverse-log-order' checked></input>
  61. <label for='cb-reverse-log-order' id='lbl-reverse-log-order'>Reverse log order</label>
  62. </span>
  63. </div>
  64. <div id='test-output'>
  65. </div>
  66. <div id='tips'>
  67. <strong>Tips:</strong>
  68. <ul>
  69. <li>Control-click the flags to (de)select multiple flags.</li>
  70. <li>The <tt>--big-transactions</tt> flag is important for two
  71. of the bigger tests. Without it, those tests create many
  72. thousands of implicit transactions, reducing the affected
  73. tests to an absolute crawl, in particular with OPFS.
  74. </li>
  75. <li>The easiest way to try different optimization levels is,
  76. from this directory:
  77. <pre>$ rm -f jswasm/speedtest1.js; make -e emcc_opt='-O2' speedtest1</pre>
  78. Then reload this page. -O2 seems to consistently produce the fastest results.
  79. </li>
  80. </ul>
  81. </div>
  82. <style>
  83. #test-output {
  84. white-space: break-spaces;
  85. overflow: auto;
  86. }
  87. div#tips { margin-top: 1em; }
  88. #toolbar {
  89. display: flex;
  90. flex-direction: row;
  91. flex-wrap: wrap;
  92. }
  93. #toolbar > * {
  94. margin: 0 0.5em;
  95. }
  96. .toolbar-inner-vertical {
  97. display: flex;
  98. flex-direction: column;
  99. justify-content: space-between;
  100. }
  101. #toolbar-select {
  102. display: flex;
  103. flex-direction: column;
  104. }
  105. .toolbar-inner-vertical > *, #toolbar-select > * {
  106. margin: 0.2em 0;
  107. }
  108. #select-flags > option {
  109. white-space: pre;
  110. font-family: monospace;
  111. }
  112. fieldset {
  113. border-radius: 0.5em;
  114. }
  115. #toolbar-runner-controls { flex-grow: 1 }
  116. #toolbar-runner-controls > * { flex: 1 0 auto }
  117. #toolbar-selected-flags::before {
  118. font-family: initial;
  119. content:"Selected flags: ";
  120. }
  121. #toolbar-selected-flags {
  122. display: flex;
  123. flex-direction: column;
  124. font-family: monospace;
  125. justify-content: flex-start;
  126. }
  127. </style>
  128. <script>(function(){
  129. 'use strict';
  130. const E = (sel)=>document.querySelector(sel);
  131. const eOut = E('#test-output');
  132. const log2 = function(cssClass,...args){
  133. let ln;
  134. if(1 || cssClass){
  135. ln = document.createElement('div');
  136. if(cssClass) ln.classList.add(cssClass);
  137. ln.append(document.createTextNode(args.join(' ')));
  138. }else{
  139. // This doesn't work with the "reverse order" option!
  140. ln = document.createTextNode(args.join(' ')+'\n');
  141. }
  142. eOut.append(ln);
  143. };
  144. const log = (...args)=>{
  145. //console.log(...args);
  146. log2('', ...args);
  147. };
  148. const logErr = function(...args){
  149. console.error(...args);
  150. log2('error', ...args);
  151. };
  152. const logWarn = function(...args){
  153. console.warn(...args);
  154. log2('warning', ...args);
  155. };
  156. const spacePad = function(str,len=21){
  157. if(str.length===len) return str;
  158. else if(str.length>len) return str.substr(0,len);
  159. const a = []; a.length = len - str.length;
  160. return str+a.join(' ');
  161. };
  162. // OPTION elements seem to ignore white-space:pre, so do this the hard way...
  163. const nbspPad = function(str,len=21){
  164. if(str.length===len) return str;
  165. else if(str.length>len) return str.substr(0,len);
  166. const a = []; a.length = len - str.length;
  167. return str+a.join('&nbsp;');
  168. };
  169. const urlParams = new URL(self.location.href).searchParams;
  170. const W = new Worker(
  171. "speedtest1-worker.js?sqlite3.dir=jswasm"+
  172. (urlParams.has('opfs-verbose') ? '&opfs-verbose' : '')+
  173. (urlParams.has('opfs-disable') ? '&opfs-disable' : '')
  174. );
  175. const mPost = function(msgType,payload){
  176. W.postMessage({type: msgType, data: payload});
  177. };
  178. const eFlags = E('#select-flags');
  179. const eSelectedFlags = E('#toolbar-selected-flags');
  180. const eLinkMainThread = E('#link-main-thread');
  181. const eLinkWasmfs = E('#link-wasmfs');
  182. const eLinkKvvfs = E('#link-kvvfs');
  183. const getSelectedFlags = ()=>{
  184. const f = Array.prototype.map.call(eFlags.selectedOptions, (v)=>v.value);
  185. [
  186. 'size', 'vfs', 'journal', 'cachesize'
  187. ].forEach(function(k){
  188. if(urlParams.has(k)) f.push('--'+k, urlParams.get(k));
  189. });
  190. return f;
  191. };
  192. const updateSelectedFlags = function(){
  193. eSelectedFlags.innerText = '';
  194. const flags = getSelectedFlags();
  195. flags.forEach(function(f){
  196. const e = document.createElement('span');
  197. e.innerText = f;
  198. eSelectedFlags.appendChild(e);
  199. });
  200. const rxStripDash = /^(-+)?/;
  201. const comma = flags.join(',');
  202. eLinkMainThread.setAttribute('target', 'speedtest1-main-'+comma);
  203. eLinkMainThread.href = 'speedtest1.html?flags='+comma;
  204. eLinkWasmfs.setAttribute('target', 'speedtest1-wasmfs-'+comma);
  205. eLinkWasmfs.href = 'speedtest1-wasmfs.html?flags='+comma;
  206. eLinkKvvfs.setAttribute('target', 'speedtest1-kvvfs-'+comma);
  207. eLinkKvvfs.href = 'speedtest1.html?vfs=kvvfs&flags='+comma;
  208. };
  209. eFlags.addEventListener('change', updateSelectedFlags );
  210. {
  211. const flags = Object.create(null);
  212. /* TODO? Flags which require values need custom UI
  213. controls and some of them make little sense here
  214. (e.g. --script FILE). */
  215. flags["--autovacuum"] = "Enable AUTOVACUUM mode";
  216. flags["--big-transactions"] = "Important for tests 410 and 510!";
  217. //flags["--cachesize"] = "N Set the cache size to N pages";
  218. flags["--checkpoint"] = "Run PRAGMA wal_checkpoint after each test case";
  219. flags["--exclusive"] = "Enable locking_mode=EXCLUSIVE";
  220. flags["--explain"] = "Like --sqlonly but with added EXPLAIN keywords";
  221. //flags["--heap"] = "SZ MIN Memory allocator uses SZ bytes & min allocation MIN";
  222. flags["--incrvacuum"] = "Enable incremenatal vacuum mode";
  223. //flags["--journal"] = "M Set the journal_mode to M";
  224. //flags["--key"] = "KEY Set the encryption key to KEY";
  225. //flags["--lookaside"] = "N SZ Configure lookaside for N slots of SZ bytes each";
  226. flags["--memdb"] = "Use an in-memory database";
  227. //flags["--mmap"] = "SZ MMAP the first SZ bytes of the database file";
  228. flags["--multithread"] = "Set multithreaded mode";
  229. flags["--nomemstat"] = "Disable memory statistics";
  230. flags["--nomutex"] = "Open db with SQLITE_OPEN_NOMUTEX";
  231. flags["--nosync"] = "Set PRAGMA synchronous=OFF";
  232. flags["--notnull"] = "Add NOT NULL constraints to table columns";
  233. //flags["--output"] = "FILE Store SQL output in FILE";
  234. //flags["--pagesize"] = "N Set the page size to N";
  235. //flags["--pcache"] = "N SZ Configure N pages of pagecache each of size SZ bytes";
  236. //flags["--primarykey"] = "Use PRIMARY KEY instead of UNIQUE where appropriate";
  237. //flags["--repeat"] = "N Repeat each SELECT N times (default: 1)";
  238. flags["--reprepare"] = "Reprepare each statement upon every invocation";
  239. //flags["--reserve"] = "N Reserve N bytes on each database page";
  240. //flags["--script"] = "FILE Write an SQL script for the test into FILE";
  241. flags["--serialized"] = "Set serialized threading mode";
  242. flags["--singlethread"] = "Set single-threaded mode - disables all mutexing";
  243. flags["--sqlonly"] = "No-op. Only show the SQL that would have been run.";
  244. flags["--shrink-memory"] = "Invoke sqlite3_db_release_memory() frequently.";
  245. //flags["--size"] = "N Relative test size. Default=100";
  246. flags["--strict"] = "Use STRICT table where appropriate";
  247. flags["--stats"] = "Show statistics at the end";
  248. //flags["--temp"] = "N N from 0 to 9. 0: no temp table. 9: all temp tables";
  249. //flags["--testset"] = "T Run test-set T (main, cte, rtree, orm, fp, debug)";
  250. flags["--trace"] = "Turn on SQL tracing";
  251. //flags["--threads"] = "N Use up to N threads for sorting";
  252. /*
  253. The core API's WASM build does not support UTF16, but in
  254. this app it's not an issue because the data are not crossing
  255. JS/WASM boundaries.
  256. */
  257. flags["--utf16be"] = "Set text encoding to UTF-16BE";
  258. flags["--utf16le"] = "Set text encoding to UTF-16LE";
  259. flags["--verify"] = "Run additional verification steps.";
  260. flags["--without-rowid"] = "Use WITHOUT ROWID where appropriate";
  261. const preselectedFlags = [
  262. '--big-transactions',
  263. '--singlethread'
  264. ];
  265. if(urlParams.has('flags')){
  266. preselectedFlags.push(...urlParams.get('flags').split(','));
  267. }
  268. if(!urlParams.get('vfs')){
  269. preselectedFlags.push('--memdb');
  270. }
  271. Object.keys(flags).sort().forEach(function(f){
  272. const opt = document.createElement('option');
  273. eFlags.appendChild(opt);
  274. const lbl = nbspPad(f)+flags[f];
  275. //opt.innerText = lbl;
  276. opt.innerHTML = lbl;
  277. opt.value = f;
  278. if(preselectedFlags.indexOf(f) >= 0) opt.selected = true;
  279. });
  280. const cbReverseLog = E('#cb-reverse-log-order');
  281. const lblReverseLog = E('#lbl-reverse-log-order');
  282. if(cbReverseLog.checked){
  283. lblReverseLog.classList.add('warning');
  284. eOut.classList.add('reverse');
  285. }
  286. cbReverseLog.addEventListener('change', function(){
  287. if(this.checked){
  288. eOut.classList.add('reverse');
  289. lblReverseLog.classList.add('warning');
  290. }else{
  291. eOut.classList.remove('reverse');
  292. lblReverseLog.classList.remove('warning');
  293. }
  294. }, false);
  295. updateSelectedFlags();
  296. }
  297. E('#btn-output-clear').addEventListener('click', ()=>{
  298. eOut.innerText = '';
  299. });
  300. E('#btn-reset-flags').addEventListener('click',()=>{
  301. eFlags.value = '';
  302. updateSelectedFlags();
  303. });
  304. E('#btn-run').addEventListener('click',function(){
  305. log("Running speedtest1. UI controls will be disabled until it completes.");
  306. mPost('run', getSelectedFlags());
  307. });
  308. const eControls = E('#ui-controls');
  309. /** Update Emscripten-related UI elements while loading the module. */
  310. const updateLoadStatus = function f(text){
  311. if(!f.last){
  312. f.last = { text: '', step: 0 };
  313. const E = (cssSelector)=>document.querySelector(cssSelector);
  314. f.ui = {
  315. status: E('#module-status'),
  316. progress: E('#module-progress'),
  317. spinner: E('#module-spinner')
  318. };
  319. }
  320. if(text === f.last.text) return;
  321. f.last.text = text;
  322. if(f.ui.progress){
  323. f.ui.progress.value = f.last.step;
  324. f.ui.progress.max = f.last.step + 1;
  325. }
  326. ++f.last.step;
  327. if(text) {
  328. f.ui.status.classList.remove('hidden');
  329. f.ui.status.innerText = text;
  330. }else{
  331. if(f.ui.progress){
  332. f.ui.progress.remove();
  333. f.ui.spinner.remove();
  334. delete f.ui.progress;
  335. delete f.ui.spinner;
  336. }
  337. f.ui.status.classList.add('hidden');
  338. }
  339. };
  340. W.onmessage = function(msg){
  341. msg = msg.data;
  342. switch(msg.type){
  343. case 'ready':
  344. log("Worker is ready.");
  345. eControls.classList.remove('hidden');
  346. break;
  347. case 'stdout': log(msg.data); break;
  348. case 'stderr': logErr(msg.data); break;
  349. case 'run-start':
  350. eControls.disabled = true;
  351. log("Running speedtest1 with argv =",msg.data.join(' '));
  352. break;
  353. case 'run-end':
  354. log("speedtest1 finished.");
  355. eControls.disabled = false;
  356. // app output is in msg.data
  357. break;
  358. case 'error': logErr(msg.data); break;
  359. case 'load-status': updateLoadStatus(msg.data); break;
  360. default:
  361. logErr("Unhandled worker message type:",msg);
  362. break;
  363. }
  364. };
  365. })();</script>
  366. </body>
  367. </html>