1100b496dSstephan<!doctype html> 2100b496dSstephan<html lang="en-us"> 3100b496dSstephan <head> 4100b496dSstephan <meta charset="utf-8"> 5100b496dSstephan <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 6100b496dSstephan <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon"> 7100b496dSstephan <link rel="stylesheet" href="common/emscripten.css"/> 8100b496dSstephan <link rel="stylesheet" href="common/testing.css"/> 9100b496dSstephan <title>speedtest1.wasm</title> 10100b496dSstephan </head> 11100b496dSstephan <body> 12100b496dSstephan <header id='titlebar'><span>speedtest1.wasm</span></header> 1344a87f08Sstephan <div>See also: <a href='speedtest1-worker.html'>A Worker-thread variant of this page.</a></div> 14100b496dSstephan <!-- emscripten bits --> 15100b496dSstephan <figure id="module-spinner"> 16100b496dSstephan <div class="spinner"></div> 17100b496dSstephan <div class='center'><strong>Initializing app...</strong></div> 18100b496dSstephan <div class='center'> 19100b496dSstephan On a slow internet connection this may take a moment. If this 20100b496dSstephan message displays for "a long time", intialization may have 21100b496dSstephan failed and the JavaScript console may contain clues as to why. 22100b496dSstephan </div> 23100b496dSstephan </figure> 24100b496dSstephan <div class="emscripten" id="module-status">Downloading...</div> 25100b496dSstephan <div class="emscripten"> 26100b496dSstephan <progress value="0" max="100" id="module-progress" hidden='1'></progress> 27100b496dSstephan </div><!-- /emscripten bits --> 2844a87f08Sstephan <div class='warning'>This page starts running the main exe when it loads, which will 2944a87f08Sstephan block the UI until it finishes! Adding UI controls to manually configure and start it 3044a87f08Sstephan are TODO.</div> 31dd628ed5Sstephan </div> 32e66b2681Sstephan <div class='warning'>Achtung: running it with the dev tools open may 33e66b2681Sstephan <em>drastically</em> slow it down. For faster results, keep the dev 34e66b2681Sstephan tools closed when running it! 35dd628ed5Sstephan </div> 36e66b2681Sstephan <div>Output is delayed/buffered because we cannot update the UI while the 37e66b2681Sstephan speedtest is running. Output will appear below when ready... 38e66b2681Sstephan <div id='test-output'></div> 39100b496dSstephan <script src="common/whwasmutil.js"></script> 40100b496dSstephan <script src="common/SqliteTestUtil.js"></script> 41100b496dSstephan <script src="speedtest1.js"></script> 428fc8b5b3Sstephan <script>(function(){ 438fc8b5b3Sstephan /** 448fc8b5b3Sstephan If this environment contains OPFS, this function initializes it and 458fc8b5b3Sstephan returns the name of the dir on which OPFS is mounted, else it returns 468fc8b5b3Sstephan an empty string. 478fc8b5b3Sstephan */ 48*b5ae85ecSstephan const wasmfsDir = function f(wasmUtil){ 498fc8b5b3Sstephan if(undefined !== f._) return f._; 508fc8b5b3Sstephan const pdir = '/persistent'; 518fc8b5b3Sstephan if( !self.FileSystemHandle 528fc8b5b3Sstephan || !self.FileSystemDirectoryHandle 538fc8b5b3Sstephan || !self.FileSystemFileHandle){ 548fc8b5b3Sstephan return f._ = ""; 558fc8b5b3Sstephan } 568fc8b5b3Sstephan try{ 578fc8b5b3Sstephan if(0===wasmUtil.xCallWrapped( 5828ef9bddSstephan 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], pdir 598fc8b5b3Sstephan )){ 608fc8b5b3Sstephan return f._ = pdir; 618fc8b5b3Sstephan }else{ 628fc8b5b3Sstephan return f._ = ""; 638fc8b5b3Sstephan } 648fc8b5b3Sstephan }catch(e){ 6528ef9bddSstephan // sqlite3_wasm_init_wasmfs() is not available 668fc8b5b3Sstephan return f._ = ""; 678fc8b5b3Sstephan } 688fc8b5b3Sstephan }; 69*b5ae85ecSstephan wasmfsDir._ = undefined; 708fc8b5b3Sstephan 71100b496dSstephan const eOut = document.querySelector('#test-output'); 72dd628ed5Sstephan const log2 = function(cssClass,...args){ 73100b496dSstephan const ln = document.createElement('div'); 74100b496dSstephan if(cssClass) ln.classList.add(cssClass); 75100b496dSstephan ln.append(document.createTextNode(args.join(' '))); 76100b496dSstephan eOut.append(ln); 77100b496dSstephan //this.e.output.lastElementChild.scrollIntoViewIfNeeded(); 78100b496dSstephan }; 79e66b2681Sstephan const logList = []; 80e66b2681Sstephan const dumpLogList = function(){ 81e66b2681Sstephan logList.forEach((v)=>log2('',v)); 82e66b2681Sstephan logList.length = 0; 83e66b2681Sstephan }; 84100b496dSstephan /* can't update DOM while speedtest is running unless we run 85100b496dSstephan speedtest in a worker thread. */; 868fc8b5b3Sstephan const log = (...args)=>{ 87100b496dSstephan console.log(...args); 88e66b2681Sstephan logList.push(args.join(' ')); 89100b496dSstephan }; 90100b496dSstephan const logErr = function(...args){ 91100b496dSstephan console.error(...args); 92e66b2681Sstephan logList.push('ERROR: '+args.join(' ')); 93100b496dSstephan }; 94100b496dSstephan 95*b5ae85ecSstephan const runTests = function(sqlite3){ 96*b5ae85ecSstephan const capi = sqlite3.capi, wasm = capi.wasm; 97*b5ae85ecSstephan //console.debug('sqlite3 =',sqlite3); 988fc8b5b3Sstephan const unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]); 99*b5ae85ecSstephan const pDir = wasmfsDir(wasm); 1008fc8b5b3Sstephan if(pDir){ 1018fc8b5b3Sstephan console.warn("Persistent storage:",pDir); 1028fc8b5b3Sstephan } 103100b496dSstephan const scope = wasm.scopedAllocPush(); 104*b5ae85ecSstephan let dbFile = pDir+"/speedtest1.db"; 105*b5ae85ecSstephan const urlParams = self.SqliteTestUtil.processUrlArgs(); 106e66b2681Sstephan const argv = ["speedtest1"]; 107*b5ae85ecSstephan if('string'===typeof urlParams.vfs){ 108*b5ae85ecSstephan if(!capi.sqlite3_vfs_find(urlParams.vfs)){ 109*b5ae85ecSstephan log2('error',"Unknown VFS:",urlParams.vfs); 110*b5ae85ecSstephan return; 111*b5ae85ecSstephan } 112*b5ae85ecSstephan argv.push("--vfs", urlParams.vfs); 113*b5ae85ecSstephan log2('',"Using VFS:",urlParams.vfs); 114*b5ae85ecSstephan if('kvvfs' === urlParams.vfs){ 115*b5ae85ecSstephan urlParams.size = 1; 116*b5ae85ecSstephan dbFile = 'session'; 117*b5ae85ecSstephan log2('',"kvvfs VFS: forcing --size 1 and filename 'session'"); 118*b5ae85ecSstephan capi.sqlite3_web_kvvfs_clear('session'); 119*b5ae85ecSstephan } 120*b5ae85ecSstephan } 121*b5ae85ecSstephan [ 122*b5ae85ecSstephan 'size' 123*b5ae85ecSstephan ].forEach(function(k){ 124*b5ae85ecSstephan const v = urlParams[k]; 125*b5ae85ecSstephan if(v) argv.push('--'+k, urlParams[k]); 126*b5ae85ecSstephan }); 127*b5ae85ecSstephan if(urlParams.flags){ 128e66b2681Sstephan // transform flags=a,b,c to ["--a", "--b", "--c"] 129*b5ae85ecSstephan argv.push(...(urlParams.flags.split(',').map((v)=>'--'+v))); 130e66b2681Sstephan }else{ 131e66b2681Sstephan argv.push( 1328fc8b5b3Sstephan "--singlethread", 1331174c23eSstephan "--nomutex", 134dd628ed5Sstephan "--nosync", 135e66b2681Sstephan "--nomemstat" 136e66b2681Sstephan ); 137dd628ed5Sstephan //"--memdb", // note that memdb trumps the filename arg 13828ef9bddSstephan } 139e66b2681Sstephan argv.push("--big-transactions"/*important for tests 410 and 510!*/, 140e66b2681Sstephan dbFile); 1418fc8b5b3Sstephan console.log("argv =",argv); 142dd628ed5Sstephan // These log messages are not emitted to the UI until after main() returns. Fixing that 143dd628ed5Sstephan // requires moving the main() call and related cleanup into a timeout handler. 144e66b2681Sstephan if(pDir) unlink(dbFile); 145e66b2681Sstephan log2('',"Starting native app:\n ",argv.join(' ')); 146e66b2681Sstephan log2('',"This will take a while and the browser might warn about the runaway JS.", 147e66b2681Sstephan "Give it time..."); 148e66b2681Sstephan logList.length = 0; 149dd628ed5Sstephan setTimeout(function(){ 150*b5ae85ecSstephan wasm.xCall('wasm_main', argv.length, 1518fc8b5b3Sstephan wasm.scopedAllocMainArgv(argv)); 152100b496dSstephan wasm.scopedAllocPop(scope); 1538fc8b5b3Sstephan if(pDir) unlink(dbFile); 154e66b2681Sstephan logList.unshift("Done running native main(). Output:"); 155e66b2681Sstephan dumpLogList(); 156e66b2681Sstephan }, 50); 157dd628ed5Sstephan }/*runTests()*/; 158100b496dSstephan 1598fc8b5b3Sstephan self.sqlite3TestModule.print = log; 160100b496dSstephan self.sqlite3TestModule.printErr = logErr; 161*b5ae85ecSstephan sqlite3Speedtest1InitModule(self.sqlite3TestModule) 162*b5ae85ecSstephan .then((EmscriptenModule)=>{ 163*b5ae85ecSstephan return EmscriptenModule.sqlite3.installOpfsVfs() 164*b5ae85ecSstephan .catch((e)=>{console.warn(e.message)}) 165*b5ae85ecSstephan .then(()=>runTests(EmscriptenModule.sqlite3)); 166100b496dSstephan }); 167100b496dSstephan })(); 168100b496dSstephan </script> 169100b496dSstephan </body> 170100b496dSstephan</html> 171