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