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