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 <div>See also: <a href='speedtest1-worker.html'>A Worker-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 <div class='warning'>This page starts running the main exe when it loads, which will 29 block the UI until it finishes! Adding UI controls to manually configure and start it 30 are TODO.</div> 31 <div>Output is sent to the dev console because we cannot update the UI while the 32 speedtest is running unless/until we move the speedtest to a worker thread. 33 </div> 34 <div class='warning'>Achtung: running it with the dev tools open <em>drastically</em> 35 slows it down: by a factor of 2.5+. For faster results, keep the dev tools closed 36 when running it! 37 </div> 38 <hr> 39 <div id='test-output'> 40 </div> 41 <script src="common/whwasmutil.js"></script> 42 <script src="common/SqliteTestUtil.js"></script> 43 <script src="speedtest1.js"></script> 44 <script>(function(){ 45 /** 46 If this environment contains OPFS, this function initializes it and 47 returns the name of the dir on which OPFS is mounted, else it returns 48 an empty string. 49 */ 50 const opfsDir = function f(wasmUtil){ 51 if(undefined !== f._) return f._; 52 const pdir = '/persistent'; 53 if( !self.FileSystemHandle 54 || !self.FileSystemDirectoryHandle 55 || !self.FileSystemFileHandle){ 56 return f._ = ""; 57 } 58 try{ 59 if(0===wasmUtil.xCallWrapped( 60 'sqlite3_wasm_init_opfs', 'i32', ['string'], pdir 61 )){ 62 return f._ = pdir; 63 }else{ 64 return f._ = ""; 65 } 66 }catch(e){ 67 // sqlite3_wasm_init_opfs() is not available 68 return f._ = ""; 69 } 70 }; 71 opfsDir._ = undefined; 72 73 const eOut = document.querySelector('#test-output'); 74 const log2 = function(cssClass,...args){ 75 const ln = document.createElement('div'); 76 if(cssClass) ln.classList.add(cssClass); 77 ln.append(document.createTextNode(args.join(' '))); 78 eOut.append(ln); 79 //this.e.output.lastElementChild.scrollIntoViewIfNeeded(); 80 }; 81 const doHtmlOutput = false 82 /* can't update DOM while speedtest is running unless we run 83 speedtest in a worker thread. */; 84 const log = (...args)=>{ 85 console.log(...args); 86 if(doHtmlOutput) log2('', ...args); 87 }; 88 const logErr = function(...args){ 89 console.error(...args); 90 if(doHtmlOutput) log2('error', ...args); 91 }; 92 93 const runTests = function(EmscriptenModule){ 94 console.log("Module inited.",EmscriptenModule); 95 const wasm = { 96 exports: EmscriptenModule.asm, 97 alloc: (n)=>EmscriptenModule._malloc(n), 98 dealloc: (m)=>EmscriptenModule._free(m), 99 memory: EmscriptenModule.asm.memory || EmscriptenModule.wasmMemory 100 }; 101 //console.debug('wasm =',wasm); 102 self.WhWasmUtilInstaller(wasm); 103 const unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]); 104 const pDir = opfsDir(wasm); 105 if(pDir){ 106 console.warn("Persistent storage:",pDir); 107 } 108 const scope = wasm.scopedAllocPush(); 109 const dbFile = 0 ? "" : pDir+"/speedtest1.db"; 110 const argv = [ 111 // TODO: accept flags via URL arguments and/or a 112 // UI control. A multi-SELECT element should do 113 // nicely. 114 "speedtest1", 115 "--singlethread", 116 "--nomutex", 117 "--nosync", 118 "--nomemstat", 119 "--big-transactions", // important for tests 410 and 510! 120 //"--memdb", // note that memdb trumps the filename arg 121 dbFile 122 ]; 123 console.log("argv =",argv); 124 // These log messages are not emitted to the UI until after main() returns. Fixing that 125 // requires moving the main() call and related cleanup into a timeout handler. 126 log2('',"Starting native main() with flags:",argv.join(' ')); 127 log2('',"This will take a while and the browser might warn about the runaway JS. Give it time."); 128 setTimeout(function(){ 129 wasm.xCall('__main_argc_argv', argv.length, 130 wasm.scopedAllocMainArgv(argv)); 131 wasm.scopedAllocPop(scope); 132 if(pDir) unlink(dbFile); 133 log2('',"Done running native main(). Check dev console for output."); 134 }, 100); 135 }/*runTests()*/; 136 137 self.sqlite3TestModule.print = log; 138 self.sqlite3TestModule.printErr = logErr; 139 sqlite3Speedtest1InitModule(self.sqlite3TestModule).then(function(M){ 140 setTimeout(()=>runTests(M), 100); 141 }); 142 })(); 143 </script> 144 </body> 145</html> 146