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=BYTES 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>→ <a id='link-main-thread' href='#' target='speedtest-main' 41 title='Start speedtest1.html with the selected flags'>speedtest1</a> 42 </span> 43 <span>→ <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>→ <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 a 72 combined total of 140k implicit transactions, reducing their 73 speed to an absolute crawl, especially when WASMFS is 74 activated. 75 </li> 76 <li>The easiest way to try different optimization levels is, 77 from this directory: 78 <pre>$ rm -f speedtest1.js; make -e emcc_opt='-O2' speedtest1.js</pre> 79 Then reload this page. -O2 seems to consistently produce the fastest results. 80 </li> 81 </ul> 82 </div> 83 <style> 84 #test-output { 85 white-space: break-spaces; 86 overflow: auto; 87 } 88 div#tips { margin-top: 1em; } 89 #toolbar { 90 display: flex; 91 flex-direction: row; 92 flex-wrap: wrap; 93 } 94 #toolbar > * { 95 margin: 0 0.5em; 96 } 97 .toolbar-inner-vertical { 98 display: flex; 99 flex-direction: column; 100 justify-content: space-between; 101 } 102 #toolbar-select { 103 display: flex; 104 flex-direction: column; 105 } 106 .toolbar-inner-vertical > *, #toolbar-select > * { 107 margin: 0.2em 0; 108 } 109 #select-flags > option { 110 white-space: pre; 111 font-family: monospace; 112 } 113 fieldset { 114 border-radius: 0.5em; 115 } 116 #toolbar-runner-controls { flex-grow: 1 } 117 #toolbar-runner-controls > * { flex: 1 0 auto } 118 #toolbar-selected-flags::before { 119 font-family: initial; 120 content:"Selected flags: "; 121 } 122 #toolbar-selected-flags { 123 display: flex; 124 flex-direction: column; 125 font-family: monospace; 126 justify-content: flex-start; 127 } 128 </style> 129 <script>(function(){ 130 'use strict'; 131 const E = (sel)=>document.querySelector(sel); 132 const eOut = E('#test-output'); 133 const log2 = function(cssClass,...args){ 134 let ln; 135 if(1 || cssClass){ 136 ln = document.createElement('div'); 137 if(cssClass) ln.classList.add(cssClass); 138 ln.append(document.createTextNode(args.join(' '))); 139 }else{ 140 // This doesn't work with the "reverse order" option! 141 ln = document.createTextNode(args.join(' ')+'\n'); 142 } 143 eOut.append(ln); 144 }; 145 const log = (...args)=>{ 146 //console.log(...args); 147 log2('', ...args); 148 }; 149 const logErr = function(...args){ 150 console.error(...args); 151 log2('error', ...args); 152 }; 153 const logWarn = function(...args){ 154 console.warn(...args); 155 log2('warning', ...args); 156 }; 157 158 const spacePad = function(str,len=21){ 159 if(str.length===len) return str; 160 else if(str.length>len) return str.substr(0,len); 161 const a = []; a.length = len - str.length; 162 return str+a.join(' '); 163 }; 164 // OPTION elements seem to ignore white-space:pre, so do this the hard way... 165 const nbspPad = function(str,len=21){ 166 if(str.length===len) return str; 167 else if(str.length>len) return str.substr(0,len); 168 const a = []; a.length = len - str.length; 169 return str+a.join(' '); 170 }; 171 172 const W = new Worker("speedtest1-worker.js?sqlite3.dir=jswasm"); 173 const mPost = function(msgType,payload){ 174 W.postMessage({type: msgType, data: payload}); 175 }; 176 177 const eFlags = E('#select-flags'); 178 const eSelectedFlags = E('#toolbar-selected-flags'); 179 const eLinkMainThread = E('#link-main-thread'); 180 const eLinkWasmfs = E('#link-wasmfs'); 181 const eLinkKvvfs = E('#link-kvvfs'); 182 const urlParams = new URL(self.location.href).searchParams; 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('opfs'!==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 309 const eControls = E('#ui-controls'); 310 /** Update Emscripten-related UI elements while loading the module. */ 311 const updateLoadStatus = function f(text){ 312 if(!f.last){ 313 f.last = { text: '', step: 0 }; 314 const E = (cssSelector)=>document.querySelector(cssSelector); 315 f.ui = { 316 status: E('#module-status'), 317 progress: E('#module-progress'), 318 spinner: E('#module-spinner') 319 }; 320 } 321 if(text === f.last.text) return; 322 f.last.text = text; 323 if(f.ui.progress){ 324 f.ui.progress.value = f.last.step; 325 f.ui.progress.max = f.last.step + 1; 326 } 327 ++f.last.step; 328 if(text) { 329 f.ui.status.classList.remove('hidden'); 330 f.ui.status.innerText = text; 331 }else{ 332 if(f.ui.progress){ 333 f.ui.progress.remove(); 334 f.ui.spinner.remove(); 335 delete f.ui.progress; 336 delete f.ui.spinner; 337 } 338 f.ui.status.classList.add('hidden'); 339 } 340 }; 341 342 W.onmessage = function(msg){ 343 msg = msg.data; 344 switch(msg.type){ 345 case 'ready': 346 log("Worker is ready."); 347 eControls.classList.remove('hidden'); 348 break; 349 case 'stdout': log(msg.data); break; 350 case 'stdout': logErr(msg.data); break; 351 case 'run-start': 352 eControls.disabled = true; 353 log("Running speedtest1 with argv =",msg.data.join(' ')); 354 break; 355 case 'run-end': 356 log("speedtest1 finished."); 357 eControls.disabled = false; 358 // app output is in msg.data 359 break; 360 case 'error': logErr(msg.data); break; 361 case 'load-status': updateLoadStatus(msg.data); break; 362 default: 363 logErr("Unhandled worker message type:",msg); 364 break; 365 } 366 }; 367})();</script> 368 </body> 369</html> 370