aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/png_benchmark/index.html (4244B)


      1 <!doctype html>
      2 <html lang="en">
      3 <meta charset="utf-8">
      4 <meta name="viewport" content="width=device-width, initial-scale=1">
      5 <title>Phone PNG benchmark</title>
      6 <style>
      7   body { font: 16px system-ui; max-width: 800px; margin: 24px auto; padding: 0 16px; color: #18202a; background: #f6f8fb; }
      8   button { padding: 12px 20px; font: inherit; cursor: pointer; }
      9   table { border-collapse: collapse; width: 100%; font-size: 14px; }
     10   th, td { text-align: left; padding: 10px 6px; border-bottom: 1px solid #ccd4dd; }
     11   pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
     12 </style>
     13 <h1>Phone PNG benchmark</h1>
     14 <p>Compare WASM libpng with browser-native decoding on 180 game textures.
     15 Downloads happen first. Timings include readback and conversion to pixels in WASM,
     16 but exclude GPU upload and game loading.</p>
     17 <p>Close the game tab first and keep this page visible while it runs.
     18 One warm-up and five measured rounds usually take less than a minute.
     19 Results are saved to the benchmark server automatically.</p>
     20 <button id="run">Run benchmark</button>
     21 <p id="status" role="status">Ready.</p>
     22 <div id="results"></div>
     23 <details hidden id="details"><summary>Full results</summary><pre id="json"></pre></details>
     24 <script>
     25 const button = document.querySelector('#run');
     26 const status = document.querySelector('#status');
     27 let worker;
     28 const median = values => [...values].sort((a, b) => a - b)[Math.floor(values.length / 2)];
     29 button.onclick = () => {
     30   button.disabled = true;
     31   document.querySelector('#results').replaceChildren();
     32   document.querySelector('#details').hidden = true;
     33   worker = new Worker('worker.js');
     34   const fail = message => {
     35     status.textContent = message;
     36     worker.terminate();
     37     worker = null;
     38     button.disabled = false;
     39   };
     40   worker.onerror = event => fail(`Failed: ${event.message}`);
     41   worker.onmessage = async ({data}) => {
     42     if (data.status) status.textContent = data.status;
     43     if (data.error) { fail(`Failed: ${data.error}`); return; }
     44     if (!data.result) return;
     45     worker.terminate();
     46     worker = null;
     47     const result = data.result;
     48     const table = document.createElement('table');
     49     table.innerHTML = '<tr><th>Decoder</th><th>Median total</th><th>RGB / RGBA</th><th>Images differing</th></tr>';
     50     const names = {wasm: 'WASM libpng', bitmap: 'ImageBitmap + canvas', imageDecoder: 'ImageDecoder'};
     51     for (const mode of ['wasm', 'bitmap', 'imageDecoder']) {
     52       const stats = result.decoders[mode];
     53       const row = table.insertRow();
     54       row.insertCell().textContent = names[mode];
     55       if (stats.unsupported || stats.error) {
     56         const cell = row.insertCell();
     57         cell.colSpan = 3;
     58         cell.textContent = stats.unsupported ? 'Not supported in this browser' : stats.error;
     59         continue;
     60       }
     61       row.insertCell().textContent = median(stats.RGB.ms.map((value, i) => value + stats.RGBA.ms[i])).toFixed(1) + ' ms';
     62       row.insertCell().textContent = `${median(stats.RGB.ms).toFixed(1)} / ${median(stats.RGBA.ms).toFixed(1)} ms`;
     63       row.insertCell().textContent = `${stats.RGB.mismatchedImages}/137 RGB; ${stats.RGBA.mismatchedImages}/43 RGBA`;
     64     }
     65     document.querySelector('#results').append(table);
     66     document.querySelector('#json').textContent = JSON.stringify(result, null, 2);
     67     document.querySelector('#details').hidden = false;
     68     status.textContent = 'Benchmark complete. Saving results...';
     69     try {
     70       const response = await fetch('/results', {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(result)});
     71       if (!response.ok) throw Error(`HTTP ${response.status}`);
     72       const saved = await response.json();
     73       status.textContent = `Complete. Results saved (${saved.id}).`;
     74     } catch (error) {
     75       status.textContent = `Complete, but saving failed: ${error}. Full results are below.`;
     76     }
     77     button.disabled = false;
     78   };
     79 };
     80 
     81 // Background throttling would invalidate a phone timing comparison.
     82 document.addEventListener('visibilitychange', () => {
     83   if (document.hidden && worker) {
     84     worker.terminate();
     85     worker = null;
     86     status.textContent = 'Stopped because the page was hidden. Keep it visible and run again.';
     87     button.disabled = false;
     88   }
     89 });
     90 </script>
     91 </html>