mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add speedtest1-worker.html, an interactive Worker-thread variant of speedtest1.html. Add ext/wasm/index.html to act as a gateway to the various test pages.
FossilOrigin-Name: f16c68ee6d5ebb8dec2ab656dbab2ddb5f1d5133153ad553f986b31020adaa38
This commit is contained in:
99
ext/wasm/speedtest1-worker.js
Normal file
99
ext/wasm/speedtest1-worker.js
Normal file
@ -0,0 +1,99 @@
|
||||
'use strict';
|
||||
(function(){
|
||||
importScripts('common/whwasmutil.js','speedtest1.js');
|
||||
/**
|
||||
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 mPost = function(msgType,payload){
|
||||
postMessage({type: msgType, data: payload});
|
||||
};
|
||||
|
||||
const App = Object.create(null);
|
||||
App.logBuffer = [];
|
||||
const logMsg = (type,msgArgs)=>{
|
||||
const msg = msgArgs.join(' ');
|
||||
App.logBuffer.push(msg);
|
||||
mPost(type,msg);
|
||||
};
|
||||
const log = (...args)=>logMsg('stdout',args);
|
||||
const logErr = (...args)=>logMsg('stderr',args);
|
||||
|
||||
const runSpeedtest = function(cliFlagsArray){
|
||||
const scope = App.wasm.scopedAllocPush();
|
||||
const dbFile = 0 ? "" : App.pDir+"/speedtest1.db";
|
||||
try{
|
||||
const argv = [
|
||||
"speedtest1.wasm", ...cliFlagsArray, dbFile
|
||||
];
|
||||
App.logBuffer.length = 0;
|
||||
mPost('run-start', [...argv]);
|
||||
App.wasm.xCall('__main_argc_argv', argv.length,
|
||||
App.wasm.scopedAllocMainArgv(argv));
|
||||
}catch(e){
|
||||
mPost('error',e.message);
|
||||
}finally{
|
||||
App.wasm.scopedAllocPop(scope);
|
||||
App.unlink(dbFile);
|
||||
mPost('run-end', App.logBuffer.join('\n'));
|
||||
App.logBuffer.length = 0;
|
||||
}
|
||||
};
|
||||
|
||||
self.onmessage = function(msg){
|
||||
msg = msg.data;
|
||||
switch(msg.type){
|
||||
case 'run': runSpeedtest(msg.data || []); break;
|
||||
default:
|
||||
logErr("Unhandled worker message type:",msg.type);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const EmscriptenModule = {
|
||||
print: log,
|
||||
printErr: logErr,
|
||||
setStatus: (text)=>mPost('load-status',text)
|
||||
};
|
||||
self.sqlite3Speedtest1InitModule(EmscriptenModule).then(function(EmscriptenModule){
|
||||
log("Module inited.");
|
||||
App.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(App.wasm);
|
||||
App.unlink = App.wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]);
|
||||
App.pDir = opfsDir(App.wasm);
|
||||
if(App.pDir){
|
||||
log("Persistent storage:",pDir);
|
||||
}
|
||||
mPost('ready',true);
|
||||
});
|
||||
})();
|
Reference in New Issue
Block a user