xref: /sqlite-3.40.0/ext/wasm/speedtest1.html (revision 100b496d)
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</title>
10  </head>
11  <body>
12    <header id='titlebar'><span>speedtest1.wasm</span></header>
13    <!-- emscripten bits -->
14    <figure id="module-spinner">
15      <div class="spinner"></div>
16      <div class='center'><strong>Initializing app...</strong></div>
17      <div class='center'>
18        On a slow internet connection this may take a moment.  If this
19        message displays for "a long time", intialization may have
20        failed and the JavaScript console may contain clues as to why.
21      </div>
22    </figure>
23    <div class="emscripten" id="module-status">Downloading...</div>
24    <div class="emscripten">
25      <progress value="0" max="100" id="module-progress" hidden='1'></progress>
26    </div><!-- /emscripten bits -->
27    <div>Output is sent to the dev console because we cannot update the UI while the
28      speedtest is running unless/until we move the speedtest to a worker thread.</div>
29    <hr>
30    <div id='test-output'></div>
31    <script src="common/whwasmutil.js"></script>
32    <script src="common/SqliteTestUtil.js"></script>
33    <script src="speedtest1.js"></script>
34    <script>
35      (function(){
36        const eOut = document.querySelector('#test-output');
37        const logHtml2 = async function(cssClass,...args){
38          const ln = document.createElement('div');
39          if(cssClass) ln.classList.add(cssClass);
40          ln.append(document.createTextNode(args.join(' ')));
41          eOut.append(ln);
42          //this.e.output.lastElementChild.scrollIntoViewIfNeeded();
43        };
44        const doHtmlOutput = false
45        /* can't update DOM while speedtest is running unless we run
46           speedtest in a worker thread. */;
47        const logHtml = (...args)=>{
48          console.log(...args);
49          if(doHtmlOutput) logHtml2('', ...args);
50        };
51        const logErr = function(...args){
52          console.error(...args);
53          if(doHtmlOutput) this.logHtml2('error', ...args);
54        };
55
56        const runTests = function(EmscriptenModule){
57          console.log("Module inited.");
58          const wasm = {
59            exports: EmscriptenModule.asm,
60            alloc: (n)=>EmscriptenModule._malloc(n),
61            dealloc: (m)=>EmscriptenModule._free(m)
62          };
63          //console.debug('Emscripten Module =',EmscriptenModule);
64          //console.debug('wasm =',wasm);
65          self.WhWasmUtilInstaller(wasm);
66          const scope = wasm.scopedAllocPush();
67          try{
68            const maxArgc = 12;
69            const aArgs = [
70              // TODO: accept flags via URL arguments and/or a
71              // UI control. A multi-SELECT element should do
72              // nicely.
73              "speedtest1",
74              "--memdb",
75              "--stats"
76            ];
77            wasm.xCall('__main_argc_argv', aArgs.length,
78                       wasm.scopedAllocMainArgv(aArgs));
79          }finally{
80            wasm.scopedAllocPop(scope);
81          }
82        };
83
84        self.sqlite3TestModule.print = logHtml;
85        self.sqlite3TestModule.printErr = logErr;
86        sqlite3Speedtest1InitModule(self.sqlite3TestModule).then(function(M){
87          setTimeout(()=>runTests(M), 100);
88        });
89      })();
90    </script>
91  </body>
92</html>
93