speedtest1.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 WASMFS with OPFS, this function
  44. initializes it and returns the name of the dir on which OPFS is
  45. mounted, else it returns 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. 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. /* can't 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. const runTests = function(sqlite3){
  93. const capi = sqlite3.capi, wasm = sqlite3.wasm;
  94. //console.debug('sqlite3 =',sqlite3);
  95. const pDir = wasmfsDir(wasm);
  96. if(pDir){
  97. console.warn("Persistent storage:",pDir);
  98. }
  99. const scope = wasm.scopedAllocPush();
  100. let dbFile = pDir+"/speedtest1.db";
  101. const urlParams = new URL(self.location.href).searchParams;
  102. const argv = ["speedtest1"];
  103. if(urlParams.has('flags')){
  104. argv.push(...(urlParams.get('flags').split(',')));
  105. }
  106. let forceSize = 0;
  107. let vfs, pVfs = 0;
  108. if(urlParams.has('vfs')){
  109. vfs = urlParams.get('vfs');
  110. pVfs = capi.sqlite3_vfs_find(vfs);
  111. if(!pVfs){
  112. log2('error',"Unknown VFS:",vfs);
  113. return;
  114. }
  115. argv.push("--vfs", vfs);
  116. log2('',"Using VFS:",vfs);
  117. if('kvvfs' === vfs){
  118. forceSize = 4 /* 5 uses approx. 4.96mb */;
  119. dbFile = 'session';
  120. log2('warning',"kvvfs VFS: forcing --size",forceSize,
  121. "and filename '"+dbFile+"'.");
  122. capi.sqlite3_js_kvvfs_clear(dbFile);
  123. }
  124. }
  125. if(forceSize){
  126. argv.push('--size',forceSize);
  127. }else{
  128. [
  129. 'size'
  130. ].forEach(function(k){
  131. const v = urlParams.get(k);
  132. if(v) argv.push('--'+k, urlParams[k]);
  133. });
  134. }
  135. argv.push(
  136. "--singlethread",
  137. //"--nomutex",
  138. //"--nosync",
  139. //"--memdb", // note that memdb trumps the filename arg
  140. "--nomemstat"
  141. );
  142. argv.push("--big-transactions"/*important for tests 410 and 510!*/,
  143. dbFile);
  144. console.log("argv =",argv);
  145. // These log messages are not emitted to the UI until after main() returns. Fixing that
  146. // requires moving the main() call and related cleanup into a timeout handler.
  147. if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile);
  148. log2('',"Starting native app:\n ",argv.join(' '));
  149. log2('',"This will take a while and the browser might warn about the runaway JS.",
  150. "Give it time...");
  151. logList.length = 0;
  152. setTimeout(function(){
  153. wasm.xCall('wasm_main', argv.length,
  154. wasm.scopedAllocMainArgv(argv));
  155. wasm.scopedAllocPop(scope);
  156. if('kvvfs'===vfs){
  157. logList.unshift("KVVFS "+dbFile+" size = "+
  158. capi.sqlite3_js_kvvfs_size(dbFile));
  159. }
  160. if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile);
  161. logList.unshift("Done running native main(). Output:");
  162. dumpLogList();
  163. }, 50);
  164. }/*runTests()*/;
  165. self.sqlite3TestModule.print = log;
  166. self.sqlite3TestModule.printErr = logErr;
  167. sqlite3InitModule(self.sqlite3TestModule).then(runTests);
  168. })();</script>
  169. </body>
  170. </html>