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 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.html</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.html</a> 45 </span> 46 <span>→ <a id='link-kvvfs' href='#' target='speedtest-kvvfs' 47 title='Start speedtest1-kvvfs.html with the selected flags'>speedtest1-kvvfs.html</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"+self.location.search); 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' 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-kvvfs.html?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"; 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 'memdb', 264 'singlethread' 265 ]; 266 Object.keys(flags).sort().forEach(function(f){ 267 const opt = document.createElement('option'); 268 eFlags.appendChild(opt); 269 const lbl = nbspPad('--'+f)+flags[f]; 270 //opt.innerText = lbl; 271 opt.innerHTML = lbl; 272 opt.value = '--'+f; 273 if(preselectedFlags.indexOf(f) >= 0) opt.selected = true; 274 }); 275 276 const cbReverseLog = E('#cb-reverse-log-order'); 277 const lblReverseLog = E('#lbl-reverse-log-order'); 278 if(cbReverseLog.checked){ 279 lblReverseLog.classList.add('warning'); 280 eOut.classList.add('reverse'); 281 } 282 cbReverseLog.addEventListener('change', function(){ 283 if(this.checked){ 284 eOut.classList.add('reverse'); 285 lblReverseLog.classList.add('warning'); 286 }else{ 287 eOut.classList.remove('reverse'); 288 lblReverseLog.classList.remove('warning'); 289 } 290 }, false); 291 updateSelectedFlags(); 292 } 293 E('#btn-output-clear').addEventListener('click', ()=>{ 294 eOut.innerText = ''; 295 }); 296 E('#btn-reset-flags').addEventListener('click',()=>{ 297 eFlags.value = ''; 298 updateSelectedFlags(); 299 }); 300 E('#btn-run').addEventListener('click',function(){ 301 log("Running speedtest1. UI controls will be disabled until it completes."); 302 mPost('run', getSelectedFlags()); 303 }); 304 305 const eControls = E('#ui-controls'); 306 /** Update Emscripten-related UI elements while loading the module. */ 307 const updateLoadStatus = function f(text){ 308 if(!f.last){ 309 f.last = { text: '', step: 0 }; 310 const E = (cssSelector)=>document.querySelector(cssSelector); 311 f.ui = { 312 status: E('#module-status'), 313 progress: E('#module-progress'), 314 spinner: E('#module-spinner') 315 }; 316 } 317 if(text === f.last.text) return; 318 f.last.text = text; 319 if(f.ui.progress){ 320 f.ui.progress.value = f.last.step; 321 f.ui.progress.max = f.last.step + 1; 322 } 323 ++f.last.step; 324 if(text) { 325 f.ui.status.classList.remove('hidden'); 326 f.ui.status.innerText = text; 327 }else{ 328 if(f.ui.progress){ 329 f.ui.progress.remove(); 330 f.ui.spinner.remove(); 331 delete f.ui.progress; 332 delete f.ui.spinner; 333 } 334 f.ui.status.classList.add('hidden'); 335 } 336 }; 337 338 W.onmessage = function(msg){ 339 msg = msg.data; 340 switch(msg.type){ 341 case 'ready': 342 log("Worker is ready."); 343 eControls.classList.remove('hidden'); 344 break; 345 case 'stdout': log(msg.data); break; 346 case 'stdout': logErr(msg.data); break; 347 case 'run-start': 348 eControls.disabled = true; 349 log("Running speedtest1 with argv =",msg.data.join(' ')); 350 break; 351 case 'run-end': 352 log("speedtest1 finished."); 353 eControls.disabled = false; 354 // app output is in msg.data 355 break; 356 case 'error': logErr(msg.data); break; 357 case 'load-status': updateLoadStatus(msg.data); break; 358 default: 359 logErr("Unhandled worker message type:",msg); 360 break; 361 } 362 }; 363 })();</script> 364 </body> 365</html> 366