dd628ed58b
FossilOrigin-Name: f2846dcbcaac7880394fb14597c3a60ed310419128c4c5b863cd771a7e5cdeb5
146 lines
5.9 KiB
HTML
146 lines
5.9 KiB
HTML
<!doctype html>
|
|
<html lang="en-us">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
|
<link rel="stylesheet" href="common/emscripten.css"/>
|
|
<link rel="stylesheet" href="common/testing.css"/>
|
|
<title>speedtest1.wasm</title>
|
|
</head>
|
|
<body>
|
|
<header id='titlebar'><span>speedtest1.wasm</span></header>
|
|
<div>See also: <a href='speedtest1-worker.html'>A Worker-thread variant of this page.</a></div>
|
|
<!-- emscripten bits -->
|
|
<figure id="module-spinner">
|
|
<div class="spinner"></div>
|
|
<div class='center'><strong>Initializing app...</strong></div>
|
|
<div class='center'>
|
|
On a slow internet connection this may take a moment. If this
|
|
message displays for "a long time", intialization may have
|
|
failed and the JavaScript console may contain clues as to why.
|
|
</div>
|
|
</figure>
|
|
<div class="emscripten" id="module-status">Downloading...</div>
|
|
<div class="emscripten">
|
|
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
|
|
</div><!-- /emscripten bits -->
|
|
<div class='warning'>This page starts running the main exe when it loads, which will
|
|
block the UI until it finishes! Adding UI controls to manually configure and start it
|
|
are TODO.</div>
|
|
<div>Output is sent to the dev console because we cannot update the UI while the
|
|
speedtest is running unless/until we move the speedtest to a worker thread.
|
|
</div>
|
|
<div class='warning'>Achtung: running it with the dev tools open <em>drastically</em>
|
|
slows it down: by a factor of 2.5+. For faster results, keep the dev tools closed
|
|
when running it!
|
|
</div>
|
|
<hr>
|
|
<div id='test-output'>
|
|
</div>
|
|
<script src="common/whwasmutil.js"></script>
|
|
<script src="common/SqliteTestUtil.js"></script>
|
|
<script src="speedtest1.js"></script>
|
|
<script>(function(){
|
|
/**
|
|
If this environment contains OPFS, this function initializes it and
|
|
returns the name of the dir on which OPFS is mounted, else it returns
|
|
an empty string.
|
|
*/
|
|
const opfsDir = function f(wasmUtil){
|
|
if(undefined !== f._) return f._;
|
|
const pdir = '/persistent';
|
|
if( !self.FileSystemHandle
|
|
|| !self.FileSystemDirectoryHandle
|
|
|| !self.FileSystemFileHandle){
|
|
return f._ = "";
|
|
}
|
|
try{
|
|
if(0===wasmUtil.xCallWrapped(
|
|
'sqlite3_wasm_init_opfs', 'i32', ['string'], pdir
|
|
)){
|
|
return f._ = pdir;
|
|
}else{
|
|
return f._ = "";
|
|
}
|
|
}catch(e){
|
|
// sqlite3_wasm_init_opfs() is not available
|
|
return f._ = "";
|
|
}
|
|
};
|
|
opfsDir._ = undefined;
|
|
|
|
const eOut = document.querySelector('#test-output');
|
|
const log2 = function(cssClass,...args){
|
|
const ln = document.createElement('div');
|
|
if(cssClass) ln.classList.add(cssClass);
|
|
ln.append(document.createTextNode(args.join(' ')));
|
|
eOut.append(ln);
|
|
//this.e.output.lastElementChild.scrollIntoViewIfNeeded();
|
|
};
|
|
const doHtmlOutput = false
|
|
/* can't update DOM while speedtest is running unless we run
|
|
speedtest in a worker thread. */;
|
|
const log = (...args)=>{
|
|
console.log(...args);
|
|
if(doHtmlOutput) log2('', ...args);
|
|
};
|
|
const logErr = function(...args){
|
|
console.error(...args);
|
|
if(doHtmlOutput) log2('error', ...args);
|
|
};
|
|
|
|
const runTests = function(EmscriptenModule){
|
|
console.log("Module inited.",EmscriptenModule);
|
|
const wasm = {
|
|
exports: EmscriptenModule.asm,
|
|
alloc: (n)=>EmscriptenModule._malloc(n),
|
|
dealloc: (m)=>EmscriptenModule._free(m),
|
|
memory: EmscriptenModule.asm.memory || EmscriptenModule.wasmMemory
|
|
};
|
|
//console.debug('wasm =',wasm);
|
|
self.WhWasmUtilInstaller(wasm);
|
|
const unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]);
|
|
const pDir = opfsDir(wasm);
|
|
if(pDir){
|
|
console.warn("Persistent storage:",pDir);
|
|
}
|
|
const scope = wasm.scopedAllocPush();
|
|
const dbFile = 0 ? "" : pDir+"/speedtest1.db";
|
|
const argv = [
|
|
// TODO: accept flags via URL arguments and/or a
|
|
// UI control. A multi-SELECT element should do
|
|
// nicely.
|
|
"speedtest1",
|
|
"--singlethread",
|
|
"--nomutex",
|
|
"--nosync",
|
|
"--nomemstat",
|
|
"--big-transactions", // important for tests 410 and 510!
|
|
//"--memdb", // note that memdb trumps the filename arg
|
|
dbFile
|
|
];
|
|
console.log("argv =",argv);
|
|
// These log messages are not emitted to the UI until after main() returns. Fixing that
|
|
// requires moving the main() call and related cleanup into a timeout handler.
|
|
log2('',"Starting native main() with flags:",argv.join(' '));
|
|
log2('',"This will take a while and the browser might warn about the runaway JS. Give it time.");
|
|
setTimeout(function(){
|
|
wasm.xCall('__main_argc_argv', argv.length,
|
|
wasm.scopedAllocMainArgv(argv));
|
|
wasm.scopedAllocPop(scope);
|
|
if(pDir) unlink(dbFile);
|
|
log2('',"Done running native main(). Check dev console for output.");
|
|
}, 100);
|
|
}/*runTests()*/;
|
|
|
|
self.sqlite3TestModule.print = log;
|
|
self.sqlite3TestModule.printErr = logErr;
|
|
sqlite3Speedtest1InitModule(self.sqlite3TestModule).then(function(M){
|
|
setTimeout(()=>runTests(M), 100);
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|