| 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>→ <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'>→ <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 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 |
|
| 157 |
const spacePad = function(str,len=21){ |
| 158 |
if(str.length===len) return str; |
| 159 |
else if(str.length>len) return str.substr(0,len); |
| 160 |
const a = []; a.length = len - str.length; |
| 161 |
return str+a.join(' '); |
| 162 |
}; |
| 163 |
// OPTION elements seem to ignore white-space:pre, so do this the hard way... |
| 164 |
const nbspPad = function(str,len=21){ |
| 165 |
if(str.length===len) return str; |
| 166 |
else if(str.length>len) return str.substr(0,len); |
| 167 |
const a = []; a.length = len - str.length; |
| 168 |
return str+a.join(' '); |
| 169 |
}; |
| 170 |
|
| 171 |
const urlParams = new URL(self.location.href).searchParams; |
| 172 |
const W = new Worker( |
| 173 |
"speedtest1-worker.js?sqlite3.dir=jswasm"+ |
| 174 |
'&sqlite3.debugModule'+ |
| 175 |
(urlParams.has('opfs-verbose') ? '&opfs-verbose' : '')+ |
| 176 |
(urlParams.has('opfs-disable') ? '&opfs-disable' : '') |
| 177 |
); |
| 178 |
const mPost = function(msgType,payload){ |
| 179 |
W.postMessage({type: msgType, data: payload}); |
| 180 |
}; |
| 181 |
|
| 182 |
const eFlags = E('#select-flags'); |
| 183 |
const eSelectedFlags = E('#toolbar-selected-flags'); |
| 184 |
const eLinkMainThread = E('#link-main-thread'); |
| 185 |
const eLinkWasmfs = E('#link-wasmfs'); |
| 186 |
const eLinkKvvfs = E('#link-kvvfs'); |
| 187 |
const getSelectedFlags = ()=>{ |
| 188 |
const f = Array.prototype.map.call(eFlags.selectedOptions, (v)=>v.value); |
| 189 |
[ |
| 190 |
'size', 'vfs', 'journal', 'cachesize' |
| 191 |
].forEach(function(k){ |
| 192 |
if(urlParams.has(k)) f.push('--'+k, urlParams.get(k)); |
| 193 |
}); |
| 194 |
return f; |
| 195 |
}; |
| 196 |
const updateSelectedFlags = function(){ |
| 197 |
eSelectedFlags.innerText = ''; |
| 198 |
const flags = getSelectedFlags(); |
| 199 |
flags.forEach(function(f){ |
| 200 |
const e = document.createElement('span'); |
| 201 |
e.innerText = f; |
| 202 |
eSelectedFlags.appendChild(e); |
| 203 |
}); |
| 204 |
const rxStripDash = /^(-+)?/; |
| 205 |
const comma = flags.join(','); |
| 206 |
eLinkMainThread.setAttribute('target', 'speedtest1-main-'+comma); |
| 207 |
eLinkMainThread.href = 'speedtest1.html?flags='+comma; |
| 208 |
eLinkWasmfs.setAttribute('target', 'speedtest1-wasmfs-'+comma); |
| 209 |
eLinkWasmfs.href = 'speedtest1-wasmfs.html?flags='+comma; |
| 210 |
eLinkKvvfs.setAttribute('target', 'speedtest1-kvvfs-'+comma); |
| 211 |
eLinkKvvfs.href = 'speedtest1.html?vfs=kvvfs&flags='+comma; |
| 212 |
}; |
| 213 |
eFlags.addEventListener('change', updateSelectedFlags ); |
| 214 |
{ |
| 215 |
const flags = Object.create(null); |
| 216 |
/* TODO? Flags which require values need custom UI |
| 217 |
controls and some of them make little sense here |
| 218 |
(e.g. --script FILE). */ |
| 219 |
flags["--autovacuum"] = "Enable AUTOVACUUM mode"; |
| 220 |
flags["--big-transactions"] = "Important for tests 410 and 510!"; |
| 221 |
//flags["--cachesize"] = "N Set the cache size to N pages"; |
| 222 |
flags["--checkpoint"] = "Run PRAGMA wal_checkpoint after each test case"; |
| 223 |
flags["--exclusive"] = "Enable locking_mode=EXCLUSIVE"; |
| 224 |
flags["--explain"] = "Like --sqlonly but with added EXPLAIN keywords"; |
| 225 |
//flags["--heap"] = "SZ MIN Memory allocator uses SZ bytes & min allocation MIN"; |
| 226 |
flags["--incrvacuum"] = "Enable incremenatal vacuum mode"; |
| 227 |
//flags["--journal"] = "M Set the journal_mode to M"; |
| 228 |
//flags["--key"] = "KEY Set the encryption key to KEY"; |
| 229 |
//flags["--lookaside"] = "N SZ Configure lookaside for N slots of SZ bytes each"; |
| 230 |
flags["--memdb"] = "Use an in-memory database"; |
| 231 |
//flags["--mmap"] = "SZ MMAP the first SZ bytes of the database file"; |
| 232 |
flags["--multithread"] = "Set multithreaded mode"; |
| 233 |
flags["--nomemstat"] = "Disable memory statistics"; |
| 234 |
flags["--nomutex"] = "Open db with SQLITE_OPEN_NOMUTEX"; |
| 235 |
flags["--nosync"] = "Set PRAGMA synchronous=OFF"; |
| 236 |
flags["--notnull"] = "Add NOT NULL constraints to table columns"; |
| 237 |
//flags["--output"] = "FILE Store SQL output in FILE"; |
| 238 |
//flags["--pagesize"] = "N Set the page size to N"; |
| 239 |
//flags["--pcache"] = "N SZ Configure N pages of pagecache each of size SZ bytes"; |
| 240 |
//flags["--primarykey"] = "Use PRIMARY KEY instead of UNIQUE where appropriate"; |
| 241 |
//flags["--repeat"] = "N Repeat each SELECT N times (default: 1)"; |
| 242 |
flags["--reprepare"] = "Reprepare each statement upon every invocation"; |
| 243 |
//flags["--reserve"] = "N Reserve N bytes on each database page"; |
| 244 |
//flags["--script"] = "FILE Write an SQL script for the test into FILE"; |
| 245 |
flags["--serialized"] = "Set serialized threading mode"; |
| 246 |
flags["--singlethread"] = "Set single-threaded mode - disables all mutexing"; |
| 247 |
flags["--sqlonly"] = "No-op. Only show the SQL that would have been run."; |
| 248 |
flags["--shrink-memory"] = "Invoke sqlite3_db_release_memory() frequently."; |
| 249 |
//flags["--size"] = "N Relative test size. Default=100"; |
| 250 |
flags["--strict"] = "Use STRICT table where appropriate"; |
| 251 |
flags["--stats"] = "Show statistics at the end"; |
| 252 |
//flags["--temp"] = "N N from 0 to 9. 0: no temp table. 9: all temp tables"; |
| 253 |
//flags["--testset"] = "T Run test-set T (main, cte, rtree, orm, fp, debug)"; |
| 254 |
flags["--trace"] = "Turn on SQL tracing"; |
| 255 |
//flags["--threads"] = "N Use up to N threads for sorting"; |
| 256 |
/* |
| 257 |
The core API's WASM build does not support UTF16, but in |
| 258 |
this app it's not an issue because the data are not crossing |
| 259 |
JS/WASM boundaries. |
| 260 |
*/ |
| 261 |
flags["--utf16be"] = "Set text encoding to UTF-16BE"; |
| 262 |
flags["--utf16le"] = "Set text encoding to UTF-16LE"; |
| 263 |
flags["--verify"] = "Run additional verification steps."; |
| 264 |
flags["--without-rowid"] = "Use WITHOUT ROWID where appropriate"; |
| 265 |
const preselectedFlags = [ |
| 266 |
'--big-transactions', |
| 267 |
'--singlethread' |
| 268 |
]; |
| 269 |
if(urlParams.has('flags')){ |
| 270 |
preselectedFlags.push(...urlParams.get('flags').split(',')); |
| 271 |
} |
| 272 |
if(!urlParams.get('vfs')){ |
| 273 |
preselectedFlags.push('--memdb'); |
| 274 |
} |
| 275 |
Object.keys(flags).sort().forEach(function(f){ |
| 276 |
const opt = document.createElement('option'); |
| 277 |
eFlags.appendChild(opt); |
| 278 |
const lbl = nbspPad(f)+flags[f]; |
| 279 |
//opt.innerText = lbl; |
| 280 |
opt.innerHTML = lbl; |
| 281 |
opt.value = f; |
| 282 |
if(preselectedFlags.indexOf(f) >= 0) opt.selected = true; |
| 283 |
}); |
| 284 |
const cbReverseLog = E('#cb-reverse-log-order'); |
| 285 |
const lblReverseLog = E('#lbl-reverse-log-order'); |
| 286 |
if(cbReverseLog.checked){ |
| 287 |
lblReverseLog.classList.add('warning'); |
| 288 |
eOut.classList.add('reverse'); |
| 289 |
} |
| 290 |
cbReverseLog.addEventListener('change', function(){ |
| 291 |
if(this.checked){ |
| 292 |
eOut.classList.add('reverse'); |
| 293 |
lblReverseLog.classList.add('warning'); |
| 294 |
}else{ |
| 295 |
eOut.classList.remove('reverse'); |
| 296 |
lblReverseLog.classList.remove('warning'); |
| 297 |
} |
| 298 |
}, false); |
| 299 |
updateSelectedFlags(); |
| 300 |
} |
| 301 |
E('#btn-output-clear').addEventListener('click', ()=>{ |
| 302 |
eOut.innerText = ''; |
| 303 |
}); |
| 304 |
E('#btn-reset-flags').addEventListener('click',()=>{ |
| 305 |
eFlags.value = ''; |
| 306 |
updateSelectedFlags(); |
| 307 |
}); |
| 308 |
E('#btn-run').addEventListener('click',function(){ |
| 309 |
log("Running speedtest1. UI controls will be disabled until it completes."); |
| 310 |
mPost('run', getSelectedFlags()); |
| 311 |
}); |
| 312 |
|
| 313 |
const eControls = E('#ui-controls'); |
| 314 |
/** Update Emscripten-related UI elements while loading the module. */ |
| 315 |
const updateLoadStatus = function f(text){ |
| 316 |
if(!f.last){ |
| 317 |
f.last = { text: '', step: 0 }; |
| 318 |
const E = (cssSelector)=>document.querySelector(cssSelector); |
| 319 |
f.ui = { |
| 320 |
status: E('#module-status'), |
| 321 |
progress: E('#module-progress'), |
| 322 |
spinner: E('#module-spinner') |
| 323 |
}; |
| 324 |
} |
| 325 |
if(text === f.last.text) return; |
| 326 |
f.last.text = text; |
| 327 |
if(f.ui.progress){ |
| 328 |
f.ui.progress.value = f.last.step; |
| 329 |
f.ui.progress.max = f.last.step + 1; |
| 330 |
} |
| 331 |
++f.last.step; |
| 332 |
if(text) { |
| 333 |
f.ui.status.classList.remove('hidden'); |
| 334 |
f.ui.status.innerText = text; |
| 335 |
}else{ |
| 336 |
if(f.ui.progress){ |
| 337 |
f.ui.progress.remove(); |
| 338 |
f.ui.spinner.remove(); |
| 339 |
delete f.ui.progress; |
| 340 |
delete f.ui.spinner; |
| 341 |
} |
| 342 |
f.ui.status.classList.add('hidden'); |
| 343 |
} |
| 344 |
}; |
| 345 |
|
| 346 |
W.onmessage = function(msg){ |
| 347 |
msg = msg.data; |
| 348 |
switch(msg.type){ |
| 349 |
case 'ready': |
| 350 |
log("Worker is ready."); |
| 351 |
eControls.classList.remove('hidden'); |
| 352 |
break; |
| 353 |
case 'stdout': log(msg.data); break; |
| 354 |
case 'stderr': logErr(msg.data); break; |
| 355 |
case 'run-start': |
| 356 |
eControls.disabled = true; |
| 357 |
log("Running speedtest1 with argv =",msg.data.join(' ')); |
| 358 |
break; |
| 359 |
case 'run-end': |
| 360 |
log("speedtest1 finished."); |
| 361 |
eControls.disabled = false; |
| 362 |
// app output is in msg.data |
| 363 |
break; |
| 364 |
case 'error': logErr(msg.data); break; |
| 365 |
case 'load-status': updateLoadStatus(msg.data); break; |
| 366 |
default: |
| 367 |
logErr("Unhandled worker message type:",msg); |
| 368 |
break; |
| 369 |
} |
| 370 |
}; |
| 371 |
})();</script> |
| 372 |
</body> |
| 373 |
</html> |