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> 32 <div class='warning'>Achtung: running it with the dev tools open may 33 <em>drastically</em> slow it down. For faster results, keep the dev 34 tools closed when running it! 35 </div> 36 <div>Output is delayed/buffered because we cannot update the UI while the 37 speedtest is running. Output will appear below when ready... 38 <div id='test-output'></div> 39 <script src="common/SqliteTestUtil.js"></script> 40 <script src="jswasm/speedtest1.js"></script> 41 <script>(function(){ 42 /** 43 If this environment contains OPFS, this function initializes it and 44 returns the name of the dir on which OPFS is mounted, else it returns 45 an empty string. 46 */ 47 const wasmfsDir = function f(wasmUtil){ 48 if(undefined !== f._) return f._; 49 const pdir = '/persistent'; 50 if( !self.FileSystemHandle 51 || !self.FileSystemDirectoryHandle 52 || !self.FileSystemFileHandle){ 53 return f._ = ""; 54 } 55 try{ 56 if(0===wasmUtil.xCallWrapped( 57 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], pdir 58 )){ 59 return f._ = pdir; 60 }else{ 61 return f._ = ""; 62 } 63 }catch(e){ 64 // sqlite3_wasm_init_wasmfs() is not available 65 return f._ = ""; 66 } 67 }; 68 wasmfsDir._ = undefined; 69 70 const eOut = document.querySelector('#test-output'); 71 const log2 = function(cssClass,...args){ 72 const ln = document.createElement('div'); 73 if(cssClass) ln.classList.add(cssClass); 74 ln.append(document.createTextNode(args.join(' '))); 75 eOut.append(ln); 76 //this.e.output.lastElementChild.scrollIntoViewIfNeeded(); 77 }; 78 const logList = []; 79 const dumpLogList = function(){ 80 logList.forEach((v)=>log2('',v)); 81 logList.length = 0; 82 }; 83 /* can't update DOM while speedtest is running unless we run 84 speedtest in a worker thread. */; 85 const log = (...args)=>{ 86 console.log(...args); 87 logList.push(args.join(' ')); 88 }; 89 const logErr = function(...args){ 90 console.error(...args); 91 logList.push('ERROR: '+args.join(' ')); 92 }; 93 94 const runTests = function(sqlite3){ 95 const capi = sqlite3.capi, wasm = sqlite3.wasm; 96 //console.debug('sqlite3 =',sqlite3); 97 const pDir = wasmfsDir(wasm); 98 if(pDir){ 99 console.warn("Persistent storage:",pDir); 100 } 101 const scope = wasm.scopedAllocPush(); 102 let dbFile = pDir+"/speedtest1.db"; 103 const urlParams = new URL(self.location.href).searchParams; 104 const argv = ["speedtest1"]; 105 if(urlParams.has('flags')){ 106 argv.push(...(urlParams.get('flags').split(','))); 107 } 108 109 let forceSize = 0; 110 let vfs, pVfs = 0; 111 if(urlParams.has('vfs')){ 112 vfs = urlParams.get('vfs'); 113 pVfs = capi.sqlite3_vfs_find(vfs); 114 if(!pVfs){ 115 log2('error',"Unknown VFS:",vfs); 116 return; 117 } 118 argv.push("--vfs", vfs); 119 log2('',"Using VFS:",vfs); 120 if('kvvfs' === vfs){ 121 forceSize = 4 /* 5 uses approx. 4.96mb */; 122 dbFile = 'session'; 123 log2('warning',"kvvfs VFS: forcing --size",forceSize, 124 "and filename '"+dbFile+"'."); 125 capi.sqlite3_js_kvvfs_clear(dbFile); 126 } 127 } 128 if(forceSize){ 129 argv.push('--size',forceSize); 130 }else{ 131 [ 132 'size' 133 ].forEach(function(k){ 134 const v = urlParams.get(k); 135 if(v) argv.push('--'+k, urlParams[k]); 136 }); 137 } 138 argv.push( 139 "--singlethread", 140 //"--nomutex", 141 //"--nosync", 142 //"--memdb", // note that memdb trumps the filename arg 143 "--nomemstat" 144 ); 145 argv.push("--big-transactions"/*important for tests 410 and 510!*/, 146 dbFile); 147 console.log("argv =",argv); 148 // These log messages are not emitted to the UI until after main() returns. Fixing that 149 // requires moving the main() call and related cleanup into a timeout handler. 150 if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile); 151 log2('',"Starting native app:\n ",argv.join(' ')); 152 log2('',"This will take a while and the browser might warn about the runaway JS.", 153 "Give it time..."); 154 logList.length = 0; 155 setTimeout(function(){ 156 wasm.xCall('wasm_main', argv.length, 157 wasm.scopedAllocMainArgv(argv)); 158 wasm.scopedAllocPop(scope); 159 if('kvvfs'===vfs){ 160 logList.unshift("KVVFS "+dbFile+" size = "+ 161 capi.sqlite3_js_kvvfs_size(dbFile)); 162 } 163 if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile); 164 logList.unshift("Done running native main(). Output:"); 165 dumpLogList(); 166 }, 50); 167 }/*runTests()*/; 168 169 self.sqlite3TestModule.print = log; 170 self.sqlite3TestModule.printErr = logErr; 171 sqlite3InitModule(self.sqlite3TestModule).then(runTests); 172})();</script> 173</body> 174</html> 175