144a87f08Sstephan<!doctype html>
244a87f08Sstephan<html lang="en-us">
344a87f08Sstephan  <head>
444a87f08Sstephan    <meta charset="utf-8">
544a87f08Sstephan    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
644a87f08Sstephan    <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
744a87f08Sstephan    <link rel="stylesheet" href="common/emscripten.css"/>
844a87f08Sstephan    <link rel="stylesheet" href="common/testing.css"/>
944a87f08Sstephan    <title>speedtest1.wasm Worker</title>
1044a87f08Sstephan  </head>
1144a87f08Sstephan  <body>
1244a87f08Sstephan    <header id='titlebar'>speedtest1.wasm Worker</header>
1344a87f08Sstephan    <div>See also: <a href='speedtest1.html'>A main-thread variant of this page.</a></div>
1444a87f08Sstephan    <!-- emscripten bits -->
1544a87f08Sstephan    <figure id="module-spinner">
1644a87f08Sstephan      <div class="spinner"></div>
1744a87f08Sstephan      <div class='center'><strong>Initializing app...</strong></div>
1844a87f08Sstephan      <div class='center'>
1944a87f08Sstephan        On a slow internet connection this may take a moment.  If this
2044a87f08Sstephan        message displays for "a long time", intialization may have
2144a87f08Sstephan        failed and the JavaScript console may contain clues as to why.
2244a87f08Sstephan      </div>
2344a87f08Sstephan    </figure>
2444a87f08Sstephan    <div class="emscripten" id="module-status">Downloading...</div>
2544a87f08Sstephan    <div class="emscripten">
2644a87f08Sstephan      <progress value="0" max="100" id="module-progress" hidden='1'></progress>
2744a87f08Sstephan    </div><!-- /emscripten bits -->
2844a87f08Sstephan    <fieldset id='ui-controls' class='hidden'>
2944a87f08Sstephan      <legend>Options</legend>
3044a87f08Sstephan      <div id='toolbar'>
3144a87f08Sstephan        <div id='toolbar-select'>
3244a87f08Sstephan          <select id='select-flags' size='10' multiple></select>
3344a87f08Sstephan          <div>TODO? Options which require values are not represented here.</div>
3444a87f08Sstephan        </div>
35e66b2681Sstephan        <div class='toolbar-inner-vertical'>
36e66b2681Sstephan          <div id='toolbar-selected-flags'></div>
37*28ef9bddSstephan          <div class='toolbar-inner-vertical'>
38*28ef9bddSstephan            <span>&rarr; <a id='link-main-thread' href='#' target='speedtest-main'
39e66b2681Sstephan                            title='Start speedtest1.html with the selected flags'>speedtest1.html</a>
40e66b2681Sstephan            </span>
41*28ef9bddSstephan            <span>&rarr; <a id='link-wasmfs' href='#' target='speedtest-wasmfs'
42*28ef9bddSstephan                            title='Start speedtest1-wasmfs.html with the selected flags'>speedtest1-wasmfs.html</a>
43*28ef9bddSstephan            </span>
44*28ef9bddSstephan          </div>
4544a87f08Sstephan        </div>
4644a87f08Sstephan        <div class='toolbar-inner-vertical' id='toolbar-runner-controls'>
4744a87f08Sstephan          <button id='btn-reset-flags'>Reset Flags</button>
4844a87f08Sstephan          <button id='btn-output-clear'>Clear output</button>
4944a87f08Sstephan          <button id='btn-run'>Run</button>
5044a87f08Sstephan        </div>
5144a87f08Sstephan      </div>
5244a87f08Sstephan    </fieldset>
5344a87f08Sstephan    <div>
5444a87f08Sstephan      <span class='input-wrapper'>
5544a87f08Sstephan        <input type='checkbox' class='disable-during-eval' id='cb-reverse-log-order' checked></input>
5644a87f08Sstephan        <label for='cb-reverse-log-order' id='lbl-reverse-log-order'>Reverse log order</label>
5744a87f08Sstephan      </span>
5844a87f08Sstephan    </div>
591174c23eSstephan    <div id='test-output'>
601174c23eSstephan    </div>
611174c23eSstephan    <div id='tips'>
621174c23eSstephan      <strong>Tips:</strong>
631174c23eSstephan      <ul>
641174c23eSstephan        <li>Control-click the flags to (de)select multiple flags.</li>
65f5bf66c8Sstephan        <li>The <tt>--big-transactions</tt> flag is important for two
66f5bf66c8Sstephan          of the bigger tests. Without it, those tests create a
67f5bf66c8Sstephan          combined total of 140k implicit transactions, reducing their
68f5bf66c8Sstephan          speed to an absolute crawl, especially when WASMFS is
69f5bf66c8Sstephan          activated.
70f5bf66c8Sstephan        </li>
711174c23eSstephan        <li>The easiest way to try different optimization levels is,
721174c23eSstephan          from this directory:
731174c23eSstephan          <pre>$ rm -f speedtest1.js; make -e emcc_opt='-O2' speedtest1.js</pre>
741174c23eSstephan          Then reload this page. -O2 seems to consistently produce the fastest results.
751174c23eSstephan        </li>
761174c23eSstephan        </ul>
771174c23eSstephan    </div>
7844a87f08Sstephan    <style>
7944a87f08Sstephan      #test-output {
8044a87f08Sstephan          white-space: break-spaces;
8144a87f08Sstephan          overflow: auto;
8244a87f08Sstephan      }
831174c23eSstephan      div#tips { margin-top: 1em; }
8444a87f08Sstephan      #toolbar {
8544a87f08Sstephan          display: flex;
8644a87f08Sstephan          flex-direction: row;
8744a87f08Sstephan          flex-wrap: wrap;
8844a87f08Sstephan      }
8944a87f08Sstephan      #toolbar > * {
9044a87f08Sstephan          margin: 0 0.5em;
9144a87f08Sstephan      }
9244a87f08Sstephan      .toolbar-inner-vertical {
9344a87f08Sstephan          display: flex;
9444a87f08Sstephan          flex-direction: column;
9544a87f08Sstephan          justify-content: space-between;
9644a87f08Sstephan      }
9744a87f08Sstephan      #toolbar-select {
9844a87f08Sstephan          display: flex;
9944a87f08Sstephan          flex-direction: column;
10044a87f08Sstephan      }
10144a87f08Sstephan      .toolbar-inner-vertical > *, #toolbar-select > * {
10244a87f08Sstephan          margin: 0.2em 0;
10344a87f08Sstephan      }
10444a87f08Sstephan      #select-flags > option {
10544a87f08Sstephan          white-space: pre;
10644a87f08Sstephan          font-family: monospace;
10744a87f08Sstephan      }
10844a87f08Sstephan      fieldset {
10944a87f08Sstephan          border-radius: 0.5em;
11044a87f08Sstephan      }
11144a87f08Sstephan      #toolbar-runner-controls { flex-grow: 1 }
11244a87f08Sstephan      #toolbar-runner-controls > * { flex: 1 0 auto }
11344a87f08Sstephan      #toolbar-selected-flags::before {
11444a87f08Sstephan        font-family: initial;
11544a87f08Sstephan        content:"Selected flags: ";
11644a87f08Sstephan      }
11744a87f08Sstephan      #toolbar-selected-flags {
118e66b2681Sstephan        display: flex;
119e66b2681Sstephan        flex-direction: column;
12044a87f08Sstephan        font-family: monospace;
12144a87f08Sstephan        justify-content: flex-start;
12244a87f08Sstephan      }
12344a87f08Sstephan    </style>
12444a87f08Sstephan    <script>(function(){
12544a87f08Sstephan      'use strict';
12644a87f08Sstephan      const E = (sel)=>document.querySelector(sel);
12744a87f08Sstephan      const eOut = E('#test-output');
12844a87f08Sstephan      const log2 = function(cssClass,...args){
12944a87f08Sstephan        let ln;
13044a87f08Sstephan        if(1 || cssClass){
13144a87f08Sstephan          ln = document.createElement('div');
13244a87f08Sstephan          if(cssClass) ln.classList.add(cssClass);
13344a87f08Sstephan          ln.append(document.createTextNode(args.join(' ')));
13444a87f08Sstephan        }else{
13544a87f08Sstephan          // This doesn't work with the "reverse order" option!
13644a87f08Sstephan          ln = document.createTextNode(args.join(' ')+'\n');
13744a87f08Sstephan        }
13844a87f08Sstephan        eOut.append(ln);
13944a87f08Sstephan      };
14044a87f08Sstephan      const log = (...args)=>{
14144a87f08Sstephan        //console.log(...args);
14244a87f08Sstephan        log2('', ...args);
14344a87f08Sstephan      };
14444a87f08Sstephan      const logErr = function(...args){
14544a87f08Sstephan        //console.error(...args);
14644a87f08Sstephan        log2('error', ...args);
14744a87f08Sstephan      };
14844a87f08Sstephan      const logWarn = function(...args){
14944a87f08Sstephan        //console.warn(...args);
15044a87f08Sstephan        log2('warning', ...args);
15144a87f08Sstephan      };
15244a87f08Sstephan
153e66b2681Sstephan      const spacePad = function(str,len=21){
15444a87f08Sstephan        if(str.length===len) return str;
15544a87f08Sstephan        else if(str.length>len) return str.substr(0,len);
15644a87f08Sstephan        const a = []; a.length = len - str.length;
15744a87f08Sstephan        return str+a.join(' ');
15844a87f08Sstephan      };
15944a87f08Sstephan      // OPTION elements seem to ignore white-space:pre, so do this the hard way...
160e66b2681Sstephan      const nbspPad = function(str,len=21){
16144a87f08Sstephan        if(str.length===len) return str;
16244a87f08Sstephan        else if(str.length>len) return str.substr(0,len);
16344a87f08Sstephan        const a = []; a.length = len - str.length;
16444a87f08Sstephan        return str+a.join('&nbsp;');
16544a87f08Sstephan      };
16644a87f08Sstephan
16744a87f08Sstephan      const W = new Worker("speedtest1-worker.js");
16844a87f08Sstephan      const mPost = function(msgType,payload){
16944a87f08Sstephan        W.postMessage({type: msgType, data: payload});
17044a87f08Sstephan      };
17144a87f08Sstephan
17244a87f08Sstephan      const eFlags = E('#select-flags');
17344a87f08Sstephan      const eSelectedFlags = E('#toolbar-selected-flags');
174e66b2681Sstephan      const eLinkMainThread = E('#link-main-thread');
175*28ef9bddSstephan      const eLinkWasmfs = E('#link-wasmfs');
17644a87f08Sstephan      const getSelectedFlags = ()=>Array.prototype.map.call(eFlags.selectedOptions, (v)=>v.value);
17744a87f08Sstephan      const updateSelectedFlags = function(){
17844a87f08Sstephan        eSelectedFlags.innerText = '';
179e66b2681Sstephan        const flags = getSelectedFlags();
180e66b2681Sstephan        flags.forEach(function(f){
18144a87f08Sstephan          const e = document.createElement('span');
18244a87f08Sstephan          e.innerText = f;
18344a87f08Sstephan          eSelectedFlags.appendChild(e);
18444a87f08Sstephan        });
185e66b2681Sstephan        const rxStripDash = /^(-+)?/;
186e66b2681Sstephan        const comma = flags.map((v)=>v.replace(rxStripDash,'')).join(',');
187*28ef9bddSstephan        eLinkMainThread.setAttribute('target', 'speedtest1-main-'+comma);
188e66b2681Sstephan        eLinkMainThread.href = 'speedtest1.html?flags='+comma;
189*28ef9bddSstephan        eLinkWasmfs.setAttribute('target', 'speedtest1-wasmfs-'+comma);
190*28ef9bddSstephan        eLinkWasmfs.href = 'speedtest1-wasmfs.html?flags='+comma;
19144a87f08Sstephan      };
19244a87f08Sstephan      eFlags.addEventListener('change', updateSelectedFlags );
19344a87f08Sstephan      {
19444a87f08Sstephan        const flags = Object.create(null);
19544a87f08Sstephan        /* TODO? Flags which require values need custom UI
19644a87f08Sstephan           controls and some of them make little sense here
19744a87f08Sstephan           (e.g. --script FILE). */
19844a87f08Sstephan        flags["autovacuum"] = "Enable AUTOVACUUM mode";
199dd628ed5Sstephan        flags["big-transactions"] = "Important for tests 410 and 510!";
20044a87f08Sstephan        //flags["cachesize"] = "N       Set the cache size to N";
20144a87f08Sstephan        flags["checkpoint"] = "Run PRAGMA wal_checkpoint after each test case";
20244a87f08Sstephan        flags["exclusive"] = "Enable locking_mode=EXCLUSIVE";
20344a87f08Sstephan        flags["explain"] = "Like --sqlonly but with added EXPLAIN keywords";
20444a87f08Sstephan        //flags["heap"] = "SZ MIN       Memory allocator uses SZ bytes & min allocation MIN";
20544a87f08Sstephan        flags["incrvacuum"] = "Enable incremenatal vacuum mode";
20644a87f08Sstephan        //flags["journal"] = "M         Set the journal_mode to M";
20744a87f08Sstephan        //flags["key"] = "KEY           Set the encryption key to KEY";
20844a87f08Sstephan        //flags["lookaside"] = "N SZ    Configure lookaside for N slots of SZ bytes each";
20944a87f08Sstephan        flags["memdb"] = "Use an in-memory database";
21044a87f08Sstephan        //flags["mmap"] = "SZ           MMAP the first SZ bytes of the database file";
21144a87f08Sstephan        flags["multithread"] = "Set multithreaded mode";
21244a87f08Sstephan        flags["nomemstat"] = "Disable memory statistics";
2131174c23eSstephan        flags["nomutex"] = "Open db with SQLITE_OPEN_NOMUTEX";
21444a87f08Sstephan        flags["nosync"] = "Set PRAGMA synchronous=OFF";
21544a87f08Sstephan        flags["notnull"] = "Add NOT NULL constraints to table columns";
21644a87f08Sstephan        //flags["output"] = "FILE       Store SQL output in FILE";
21744a87f08Sstephan        //flags["pagesize"] = "N        Set the page size to N";
21844a87f08Sstephan        //flags["pcache"] = "N SZ       Configure N pages of pagecache each of size SZ bytes";
21944a87f08Sstephan        //flags["primarykey"] = "Use PRIMARY KEY instead of UNIQUE where appropriate";
22044a87f08Sstephan        //flags["repeat"] = "N          Repeat each SELECT N times (default: 1)";
22144a87f08Sstephan        flags["reprepare"] = "Reprepare each statement upon every invocation";
22244a87f08Sstephan        //flags["reserve"] = "N         Reserve N bytes on each database page";
22344a87f08Sstephan        //flags["script"] = "FILE       Write an SQL script for the test into FILE";
22444a87f08Sstephan        flags["serialized"] = "Set serialized threading mode";
22544a87f08Sstephan        flags["singlethread"] = "Set single-threaded mode - disables all mutexing";
22644a87f08Sstephan        flags["sqlonly"] = "No-op.  Only show the SQL that would have been run.";
22744a87f08Sstephan        flags["shrink"] = "memory     Invoke sqlite3_db_release_memory() frequently.";
22844a87f08Sstephan        //flags["size"] = "N            Relative test size.  Default=100";
22944a87f08Sstephan        flags["strict"] = "Use STRICT table where appropriate";
23044a87f08Sstephan        flags["stats"] = "Show statistics at the end";
23144a87f08Sstephan        //flags["temp"] = "N            N from 0 to 9.  0: no temp table. 9: all temp tables";
23244a87f08Sstephan        //flags["testset"] = "T         Run test-set T (main, cte, rtree, orm, fp, debug)";
23344a87f08Sstephan        flags["trace"] = "Turn on SQL tracing";
23444a87f08Sstephan        //flags["threads"] = "N         Use up to N threads for sorting";
23544a87f08Sstephan        /*
23644a87f08Sstephan          The core API's WASM build does not support UTF16, but in
23744a87f08Sstephan          this app it's not an issue because the data are not crossing
23844a87f08Sstephan          JS/WASM boundaries.
23944a87f08Sstephan        */
24044a87f08Sstephan        flags["utf16be"] = "Set text encoding to UTF-16BE";
24144a87f08Sstephan        flags["utf16le"] = "Set text encoding to UTF-16LE";
24244a87f08Sstephan        flags["verify"] = "Run additional verification steps.";
24344a87f08Sstephan        flags["without"] = "rowid     Use WITHOUT ROWID where appropriate";
24444a87f08Sstephan        const preselectedFlags = [
245dd628ed5Sstephan          'big-transactions',
246dd628ed5Sstephan          'memdb',
247dd628ed5Sstephan          'singlethread'
24844a87f08Sstephan        ];
24944a87f08Sstephan        Object.keys(flags).sort().forEach(function(f){
25044a87f08Sstephan          const opt = document.createElement('option');
25144a87f08Sstephan          eFlags.appendChild(opt);
25244a87f08Sstephan          const lbl = nbspPad('--'+f)+flags[f];
25344a87f08Sstephan          //opt.innerText = lbl;
25444a87f08Sstephan          opt.innerHTML = lbl;
25544a87f08Sstephan          opt.value = '--'+f;
25644a87f08Sstephan          if(preselectedFlags.indexOf(f) >= 0) opt.selected = true;
25744a87f08Sstephan        });
25844a87f08Sstephan
25944a87f08Sstephan        const cbReverseLog = E('#cb-reverse-log-order');
26044a87f08Sstephan        const lblReverseLog = E('#lbl-reverse-log-order');
26144a87f08Sstephan        if(cbReverseLog.checked){
26244a87f08Sstephan          lblReverseLog.classList.add('warning');
26344a87f08Sstephan          eOut.classList.add('reverse');
26444a87f08Sstephan        }
26544a87f08Sstephan        cbReverseLog.addEventListener('change', function(){
26644a87f08Sstephan          if(this.checked){
26744a87f08Sstephan            eOut.classList.add('reverse');
26844a87f08Sstephan            lblReverseLog.classList.add('warning');
26944a87f08Sstephan          }else{
27044a87f08Sstephan            eOut.classList.remove('reverse');
27144a87f08Sstephan            lblReverseLog.classList.remove('warning');
27244a87f08Sstephan          }
27344a87f08Sstephan        }, false);
27444a87f08Sstephan        updateSelectedFlags();
27544a87f08Sstephan      }
27644a87f08Sstephan      E('#btn-output-clear').addEventListener('click', ()=>{
27744a87f08Sstephan        eOut.innerText = '';
27844a87f08Sstephan      });
27944a87f08Sstephan      E('#btn-reset-flags').addEventListener('click',()=>{
28044a87f08Sstephan        eFlags.value = '';
28144a87f08Sstephan        updateSelectedFlags();
28244a87f08Sstephan      });
28344a87f08Sstephan      E('#btn-run').addEventListener('click',function(){
28444a87f08Sstephan        log("Running speedtest1. UI controls will be disabled until it completes.");
28544a87f08Sstephan        mPost('run', getSelectedFlags());
28644a87f08Sstephan      });
28744a87f08Sstephan
28844a87f08Sstephan      const eControls = E('#ui-controls');
28944a87f08Sstephan      /** Update Emscripten-related UI elements while loading the module. */
29044a87f08Sstephan      const updateLoadStatus = function f(text){
29144a87f08Sstephan        if(!f.last){
29244a87f08Sstephan          f.last = { text: '', step: 0 };
29344a87f08Sstephan          const E = (cssSelector)=>document.querySelector(cssSelector);
29444a87f08Sstephan          f.ui = {
29544a87f08Sstephan            status: E('#module-status'),
29644a87f08Sstephan            progress: E('#module-progress'),
29744a87f08Sstephan            spinner: E('#module-spinner')
29844a87f08Sstephan          };
29944a87f08Sstephan        }
30044a87f08Sstephan        if(text === f.last.text) return;
30144a87f08Sstephan        f.last.text = text;
30244a87f08Sstephan        if(f.ui.progress){
30344a87f08Sstephan          f.ui.progress.value = f.last.step;
30444a87f08Sstephan          f.ui.progress.max = f.last.step + 1;
30544a87f08Sstephan        }
30644a87f08Sstephan        ++f.last.step;
30744a87f08Sstephan        if(text) {
30844a87f08Sstephan          f.ui.status.classList.remove('hidden');
30944a87f08Sstephan          f.ui.status.innerText = text;
31044a87f08Sstephan        }else{
31144a87f08Sstephan          if(f.ui.progress){
31244a87f08Sstephan            f.ui.progress.remove();
31344a87f08Sstephan            f.ui.spinner.remove();
31444a87f08Sstephan            delete f.ui.progress;
31544a87f08Sstephan            delete f.ui.spinner;
31644a87f08Sstephan          }
31744a87f08Sstephan          f.ui.status.classList.add('hidden');
31844a87f08Sstephan        }
31944a87f08Sstephan      };
32044a87f08Sstephan
32144a87f08Sstephan      W.onmessage = function(msg){
32244a87f08Sstephan        msg = msg.data;
32344a87f08Sstephan        switch(msg.type){
3241174c23eSstephan            case 'ready':
3251174c23eSstephan              log("Worker is ready.");
3261174c23eSstephan              eControls.classList.remove('hidden');
3271174c23eSstephan              break;
32844a87f08Sstephan            case 'stdout': log(msg.data); break;
32944a87f08Sstephan            case 'stdout': logErr(msg.data); break;
33044a87f08Sstephan            case 'run-start':
33144a87f08Sstephan              eControls.disabled = true;
33244a87f08Sstephan              log("Running speedtest1 with argv =",msg.data.join(' '));
33344a87f08Sstephan              break;
3341174c23eSstephan            case 'run-end':
3351174c23eSstephan              log("speedtest1 finished.");
33644a87f08Sstephan              eControls.disabled = false;
33744a87f08Sstephan              // app output is in msg.data
33844a87f08Sstephan              break;
33944a87f08Sstephan            case 'error': logErr(msg.data); break;
34044a87f08Sstephan            case 'load-status': updateLoadStatus(msg.data); break;
34144a87f08Sstephan            default:
342dd628ed5Sstephan              logErr("Unhandled worker message type:",msg);
34344a87f08Sstephan              break;
34444a87f08Sstephan        }
34544a87f08Sstephan      };
34644a87f08Sstephan    })();</script>
34744a87f08Sstephan  </body>
34844a87f08Sstephan</html>
349