synchro du labo (0bf0da65) : app.blade.php, README.md

This commit is contained in:
cloudion
2026-11-03 22:41:15 +00:00
commit 080b308c88
2 changed files with 194 additions and 0 deletions

173
app.blade.php Normal file
View File

@@ -0,0 +1,173 @@
{{-- PL0XION benchmark ⌬ — LE BANC DE MESURE DU XERBOXION (RS-7, 26.10.2026 : « des benchmarks de mon système depuis n'importe quel appareil ;
avec ces données, optimiser tous les bions et tous les ploxions, et utiliser au mieux le compute et le processeur précis de chaque machine »).
Tourne partout où le xer tourne (navigateur, ploxi0n, l'app de bureau, un Pi). Mesure : l'appareil (cœurs, mémoire, GPU, écran), le calcul
sur un cœur et sur TOUS les cœurs (Web Workers), les entiers, la mémoire, le JSON, le DOM, le canvas, et de vrais bions du xerboxion
(jOSIcone, esc). Résultats gardés sur l'appareil ; « ↑ envoyer » (volontaire, anonyme) les dépose sur le labo ; l'admin voit tous les benchmarks, par classe d'appareil. --}}
<style>
.bm{display:flex;flex-direction:column;height:100%;background:#101113;color:#e6e4de;font-family:var(--xr-font-ui,ui-sans-serif,system-ui);overflow:hidden}
.bm__corps{flex:1;overflow:auto;padding:12px}
.bm__dock{display:flex;gap:6px;padding:8px;border-top:1px solid #23262c}
.bm__dock button{flex:1;cursor:pointer;background:#181b20;border:1px solid #2a2f37;color:#d0d4dc;border-radius:10px;padding:10px 4px;font:inherit;font-size:.76rem}
.bm__dock button.on{border-color:#5fe0c0;color:#5fe0c0}.bm__dock .go{background:#5fe0c0;color:#04120e;border:0;font-weight:800}
.bm h3{margin:14px 0 6px;font-size:.7rem;letter-spacing:.08em;text-transform:uppercase;color:#8b93a3}
.bm__l{display:flex;gap:8px;align-items:baseline;padding:6px 4px;border-bottom:1px solid #1b1e23;font-size:.82rem}
.bm__l .v{margin-left:auto;font-variant-numeric:tabular-nums;font-weight:700}.bm__l small{color:#8b93a3}
.bm__barre{height:4px;background:#1b1e23;border-radius:2px;margin:2px 4px 6px}.bm__barre i{display:block;height:100%;background:#5fe0c0;border-radius:2px}
.bm__score{font-size:2rem;font-weight:800;text-align:center;margin:10px 0 2px}.bm__sous{text-align:center;color:#8b93a3;font-size:.78rem}
.bm input{background:#181b20;border:1px solid #2a2f37;color:#e6e4de;border-radius:8px;padding:7px;font:inherit;width:100%;box-sizing:border-box}
.bm__btn{display:block;width:100%;margin-top:8px;cursor:pointer;border:0;border-radius:10px;padding:11px;background:#5fe0c0;color:#04120e;font:inherit;font-weight:800}.bm__btn:disabled{background:#2a2f37;color:#d0d4dc}
.bm__mini{margin-left:auto;cursor:pointer;background:#181b20;border:1px solid #2a2f37;color:#d0d4dc;border-radius:8px;font:inherit;font-size:.7rem;padding:3px 8px}
.bm table{width:100%;border-collapse:collapse;font-size:.74rem}.bm td,.bm th{padding:5px 4px;border-bottom:1px solid #1b1e23;text-align:right}.bm td:first-child,.bm th:first-child{text-align:left}
</style>
<script>
(function () {
'use strict';
var VERSION = 'bench-1';
function esc(s) { return window.jOSb.esc(s); }
function lire(k, d) { try { var v = JSON.parse(localStorage.getItem(k) || 'null'); return v == null ? d : v; } catch (e) { return d; } }
function ecrire(k, v) { try { localStorage.setItem(k, JSON.stringify(v)); } catch (e) {} }
function fmt(n, u) { if (n == null || !isFinite(n)) return '—'; var a = Math.abs(n), s = a >= 1e9 ? (n / 1e9).toFixed(2) + ' G' : a >= 1e6 ? (n / 1e6).toFixed(2) + ' M' : a >= 1e3 ? (n / 1e3).toFixed(1) + ' k' : n.toFixed(a < 10 ? 2 : 0) + ' '; return s + (u || ''); }
var pause = function () { return new Promise(function (r) { setTimeout(r, 30); }); };
// ── l'appareil ──
function appareil() {
var n = navigator, a = { coeurs: n.hardwareConcurrency || null, memoire_go: n.deviceMemory || null, plateforme: (n.userAgentData && n.userAgentData.platform) || n.platform || '',
navigateur: n.userAgent.slice(0, 160), ecran: screen.width + '×' + screen.height + ' @' + (window.devicePixelRatio || 1), tactile: (n.maxTouchPoints || 0) > 0 };
try { var c = document.createElement('canvas'), gl = c.getContext('webgl2') || c.getContext('webgl'); if (gl) { var d = gl.getExtension('WEBGL_debug_renderer_info');
a.gpu = d ? gl.getParameter(d.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER); a.webgl = gl instanceof (window.WebGL2RenderingContext || function () {}) ? 2 : 1; } } catch (e) {}
a.wasm = typeof WebAssembly === 'object'; a.workers = typeof Worker === 'function'; a.gpu_webgpu = !!n.gpu;
if (window.jOSNatif) a.natif = true; if (window.__TAURI__ || window.__TAURI_INTERNALS__) a.bureau = 'tauri';
a.moteur = moteur();
// (26.10, RS-7 : « lire le plus d'infos possibles pour savoir comment optimiser ») : tout ce qui pèse sur la vitesse, rien qui identifie la personne
try { var c2 = n.connection; if (c2) { a.reseau = c2.effectiveType || ''; a.debit_mbps = c2.downlink; a.rtt_ms = c2.rtt; a.economie_donnees = !!c2.saveData; } } catch (e) {}
try { if (performance.memory) a.tas_max_mo = Math.round(performance.memory.jsHeapSizeLimit / 1e6); } catch (e) {}
a.profondeur_couleur = screen.colorDepth; try { a.mouvement_reduit = matchMedia('(prefers-reduced-motion: reduce)').matches; } catch (e) {}
try { var nav = performance.getEntriesByType('navigation')[0]; if (nav) { a.page_ttfb_ms = Math.round(nav.responseStart - nav.requestStart); a.page_prete_ms = Math.round(nav.domContentLoadedEventEnd); a.page_chargee_ms = Math.round(nav.loadEventEnd || 0); }
var res = performance.getEntriesByType('resource'); a.page_ressources = res.length; a.page_poids_ko = Math.round(res.reduce(function (t, r) { return t + (r.transferSize || 0); }, 0) / 1024); } catch (e) {}
try { a.bions_charges = Object.keys(window).filter(function (k) { return /^jOS[A-Z]/.test(k); }).length; a.ploxions_charges = Object.keys(window.jOSApps || {}).length; } catch (e) {}
return a;
}
// ── la MANIÈRE dont on teste (RS-7, 26.10 : « la comparaison pas seulement de l'appareil, mais de la manière dont on teste ») ──
function moteur() {
var ua = navigator.userAgent, v = function (re) { var m = re.exec(ua); return m ? ' ' + m[1] : ''; };
if (window.jOSNatif || /ploxi0n/i.test(ua)) return 'ploxi0n (' + (/Android/.test(ua) ? 'Android' : 'iOS') + ')';
if (window.chrome && window.chrome.webview) return 'WebView2 · ' + (window.__TAURI__ || window.__TAURI_INTERNALS__ ? 'app Tauri' : 'ancien launcher') + v(/Edg\/(\d+)/);
if (window.__TAURI__ || window.__TAURI_INTERNALS__) return 'app Tauri (WebKit)';
if (navigator.brave) return 'Brave' + v(/Chrome\/(\d+)/);
if (/Edg\//.test(ua)) return 'Edge' + v(/Edg\/(\d+)/);
if (/OPR\//.test(ua)) return 'Opera' + v(/OPR\/(\d+)/);
if (/Firefox\//.test(ua)) return 'Firefox' + v(/Firefox\/(\d+)/);
if (/Chrome\//.test(ua)) return 'Chrome' + v(/Chrome\/(\d+)/);
if (/Safari\//.test(ua)) return 'Safari' + v(/Version\/(\d+)/);
return 'autre';
}
// ── les épreuves (chacune ~1 s, mesurée par performance.now) ──
function chrono(fn, ms) { var n = 0, t0 = performance.now(), t; do { n += fn(); t = performance.now(); } while (t - t0 < (ms || 900)); return n / ((t - t0) / 1000); }
var CPU_SRC = 'function f(ms){var ops=0,x=1.0001,t0=performance.now(),t;do{for(var i=0;i<20000;i++){x=Math.sqrt(x*1.0000001+i)*0.5+1;}ops+=20000;t=performance.now();}while(t-t0<ms);return [ops/((t-t0)/1000),x];}';
// le même calcul que dans les workers (la source ci-dessus), sans eval : la CSP du labo n'a pas à l'autoriser
function cpuUnCoeur(ms) { var ops = 0, x = 1.0001, t0 = performance.now(), t; do { for (var i = 0; i < 20000; i++) { x = Math.sqrt(x * 1.0000001 + i) * 0.5 + 1; } ops += 20000; t = performance.now(); } while (t - t0 < ms); return x > 0 ? ops / ((t - t0) / 1000) : 0; }
function extrasAsync(a) {
var l = [];
try { if (navigator.getBattery) l.push(navigator.getBattery().then(function (b) { a.batterie_en_charge = !!b.charging; a.batterie_niveau = Math.round(b.level * 100); }).catch(function () {})); } catch (e) {}
try { if (navigator.gpu) l.push(navigator.gpu.requestAdapter().then(function (ad) { if (!ad) return; var i = ad.info || {}; a.webgpu_fabricant = i.vendor || ''; a.webgpu_architecture = i.architecture || ''; }).catch(function () {})); } catch (e) {}
return Promise.all(l).then(function () { return a; });
}
function fps() { return new Promise(function (ok) { var n = 0, t0 = performance.now(); (function f(t) { n++; if (t - t0 < 1000) requestAnimationFrame(f); else ok(n * 1000 / (t - t0)); })(t0); setTimeout(function () { ok(n || null); }, 2500); }); }
var EPREUVES = [
{ id: 'cpu1', nom: 'calcul · 1 cœur', u: 'op/s', ref: 2e8, f: function () { return cpuUnCoeur(900); } },
{ id: 'cpuN', nom: 'calcul · tous les cœurs', u: 'op/s', ref: 1.2e9, f: function () { return tousLesCoeurs(); } },
{ id: 'entiers', nom: 'entiers (hachage FNV)', u: 'o/s', ref: 4e8, f: function () { var b = new Uint8Array(1 << 16); for (var i = 0; i < b.length; i++) b[i] = i * 31 & 255;
return chrono(function () { var h = 2166136261; for (var i = 0; i < b.length; i++) { h ^= b[i]; h = Math.imul(h, 16777619); } b[0] = h & 255; return b.length; }); } },
{ id: 'memoire', nom: 'mémoire (copie)', u: 'o/s', ref: 8e9, f: function () { var a = new Float64Array(1 << 21), c = new Float64Array(1 << 21); return chrono(function () { c.set(a); a[0] = c[1]; return a.byteLength; }); } },
{ id: 'json', nom: 'JSON (lire + écrire)', u: 'o/s', ref: 2e8, f: function () { var o = []; for (var i = 0; i < 2000; i++) o.push({ id: 'px' + i, nom: 'ploxion ' + i, tags: ['a', 'b', i], n: i * 1.5 });
var s = JSON.stringify(o); return chrono(function () { JSON.parse(JSON.stringify(JSON.parse(s))); return s.length * 2; }); } },
{ id: 'dom', nom: 'DOM (poser 500 éléments)', u: '/s', ref: 300, f: function () { var h = document.createElement('div'); h.style.cssText = 'position:absolute;left:-9999px;width:400px'; document.body.appendChild(h);
var r = chrono(function () { var s = ''; for (var i = 0; i < 500; i++) s += '<div class="x"><b>' + i + '</b><span>ploxion</span></div>'; h.innerHTML = s; void h.offsetHeight; h.innerHTML = ''; return 1; }, 700); h.remove(); return r; } },
{ id: 'canvas', nom: 'canvas 2D (formes)', u: '/s', ref: 2e5, f: function () { var c = document.createElement('canvas'); c.width = c.height = 512; var g = c.getContext('2d');
return chrono(function () { for (var i = 0; i < 200; i++) { g.fillStyle = 'hsl(' + i + ',60%,50%)'; g.beginPath(); g.arc(i * 2 % 512, i * 3 % 512, 9, 0, 6.28); g.fill(); } g.getImageData(0, 0, 1, 1); return 200; }, 700); } },
{ id: 'fps', nom: 'fluidité (images/s)', u: 'i/s', ref: 60, f: function () { return fps(); } },
{ id: 'icones', nom: 'bion jOSIcone (glyphes)', u: '/s', ref: 2e4, f: function () { if (!(window.jOSIcone && jOSIcone.px)) return null; var i = 0; return chrono(function () { for (var k = 0; k < 50; k++) jOSIcone.px('bench-' + (i++ % 500), { size: 32 }); return 50; }, 700); } },
{ id: 'esc', nom: 'bion esc (texte sûr)', u: 'o/s', ref: 1.5e8, f: function () { var t = 'Le <xerboxion> & "les ploxions" \'partout\' '.repeat(40); return chrono(function () { esc(t); return t.length; }); } }
];
function tousLesCoeurs() {
var n = Math.max(1, Math.min(32, navigator.hardwareConcurrency || 4));
if (typeof Worker !== 'function') return Promise.resolve(null);
var url = URL.createObjectURL(new Blob([CPU_SRC + 'onmessage=function(){postMessage(f(900)[0]);};'], { type: 'text/javascript' }));
return Promise.all(Array.from({ length: n }, function () { return new Promise(function (ok) { var w; try { w = new Worker(url); } catch (e) { return ok(null); }
w.onmessage = function (e) { ok(e.data); w.terminate(); }; w.onerror = function () { ok(null); w.terminate(); }; w.postMessage(0); }); }))
.then(function (l) { URL.revokeObjectURL(url); var s = l.filter(function (x) { return x; }).reduce(function (a, b) { return a + b; }, 0); return s || null; });
}
function score(m) { var l = EPREUVES.filter(function (e) { return m[e.id] > 0; }); if (!l.length) return null;
return Math.round(1000 * Math.exp(l.reduce(function (a, e) { return a + Math.log(m[e.id] / e.ref); }, 0) / l.length)); } // moyenne géométrique : 1000 = la machine de référence
function mount(container) {
var vue = 'mesurer', courant = null, enCours = false, nom = lire('xb:bench:nom', ''), aEnvoyer = null, envoye = '', parMoteur = true;
container.innerHTML = '<div class="bm"><div class="bm__corps"></div><div class="bm__dock"><button data-v="mesurer">⌬ mesurer</button><button data-v="appareil">▢ appareil</button><button data-v="comparer">≡ comparer</button><button class="go" data-go>▶ lancer</button></div></div>';
var corps = container.querySelector('.bm__corps');
function rendre() {
container.querySelectorAll('[data-v]').forEach(function (b) { b.classList.toggle('on', b.getAttribute('data-v') === vue); });
if (vue === 'appareil') { var a = appareil(); corps.innerHTML = '<h3>cet appareil</h3>' + Object.keys(a).map(function (k) { return '<div class="bm__l"><span>' + esc(k) + '</span><span class="v" style="font-weight:400;max-width:65%;text-align:right;word-break:break-word">' + esc(a[k]) + '</span></div>'; }).join('')
+ '<h3>son nom</h3><input data-nom placeholder="ex. iPhone de RS-7, Pi du salon" value="' + esc(nom) + '">'; return; }
if (vue === 'comparer') { var mes = lire('xb:bench:passages', []);
corps.innerHTML = '<h3>mes passages (cet appareil)</h3>' + tableau(mes) + '<h3>tous mes appareils (labo)</h3><div data-tous>⧗</div>';
fetch('/px/bench/resultats', { credentials: 'same-origin', headers: { Accept: 'application/json' } }).then(function (r) { return r.json(); }).then(function (d) {
var el = corps.querySelector('[data-tous]'); if (!el) return;
var lignes = (d.passages || []).map(function (p) { var a = p.appareil || {}; return { quand: p.quand * 1000, nom: (a.nom || a.gpu || a.plateforme || '?') + (a.moteur ? ' · ' + a.moteur : ''), m: p.mesures }; });
if (d.tous) { el.previousElementSibling.textContent = 'admin · tous les benchmarks (' + d.total + ')'; el.innerHTML = admin((parMoteur ? d.stats_moteur : d.stats) || []) + '<h3>les derniers passages</h3>' + tableau(lignes); }
else el.innerHTML = lignes.length ? tableau(lignes) : 'connecte-toi pour voir tous tes appareils'; })
.catch(function () { var el = corps.querySelector('[data-tous]'); if (el) el.textContent = 'hors ligne'; }); return; }
var m = courant || {};
corps.innerHTML = '<div class="bm__score">' + (m.score != null ? m.score : '⌬') + '</div><div class="bm__sous">' + (enCours ? '⧗ ' + esc(m._etape || '') : m.score != null ? 'score · 1000 = la machine de référence (moyenne géométrique)' : '▶ lancer : une quinzaine de secondes, garde l\'écran ouvert') + '</div>'
+ '<h3>les épreuves</h3>' + EPREUVES.map(function (e) { var v = m[e.id], p = v > 0 ? Math.min(100, 100 * v / (e.ref * 2)) : 0;
return '<div class="bm__l"><span>' + esc(e.nom) + '</span><span class="v">' + (v === null ? '<small>absent</small>' : v > 0 ? fmt(v, e.u) : '·') + '</span></div><div class="bm__barre"><i style="width:' + p.toFixed(1) + '%"></i></div>'; }).join('')
+ (m.coeursX ? '<div class="bm__l"><span>gain multi-cœurs</span><span class="v">×' + m.coeursX.toFixed(1) + ' <small>sur ' + (navigator.hardwareConcurrency || '?') + ' cœurs</small></span></div>' : '')
+ (m.cpu1 && m.cpu1 < 6e7 && (navigator.hardwareConcurrency || 0) >= 4 ? '<div class="bm__l"><small>△ calcul sur un cœur très lent pour cette machine : le moteur JavaScript tourne probablement sans son compilateur (JIT), par exemple le mode « sécurité renforcée » d\'Edge / WebView2. Compare avec Brave ou Chrome.</small></div>' : '')
+ (aEnvoyer ? '<h3>partager</h3><div class="bm__l"><small>Anonyme : le score, les mesures, et le type d\'appareil (cœurs, GPU, écran, navigateur). Ni nom de compte, ni adresse.</small></div>'
+ '<button class="bm__btn" data-envoyer' + (envoye ? ' disabled' : '') + '>' + (envoye || '↑ envoyer mon benchmark') + '</button>' : '');
}
// ── la vue admin : par classe d'appareil, la médiane de chaque épreuve (barres horizontales, une couleur, valeur écrite au bout) ──
function barres(titre, l, cle, u) {
var max = Math.max.apply(null, l.map(function (x) { return x[cle] || 0; }).concat([1]));
return '<div style="margin:8px 0 14px"><div style="font-size:.74rem;color:#8b93a3;margin-bottom:4px">' + esc(titre) + '</div>' + l.map(function (x) { var v = x[cle];
return '<div title="' + esc(x.classe + ' · ' + (v == null ? 'absent' : fmt(v, u)) + ' · ' + x.n + ' passage(s)') + '" style="display:flex;align-items:center;gap:8px;margin:3px 0;font-size:.74rem">'
+ '<span style="width:42%;color:#d0d4dc;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">' + esc(x.classe) + '</span>'
+ '<span style="flex:1;height:10px;position:relative"><i style="position:absolute;left:0;top:0;bottom:0;border-radius:0 4px 4px 0;background:#5fe0c0;width:' + (v ? Math.max(1, 100 * v / max).toFixed(1) : 0) + '%"></i></span>'
+ '<span style="width:5.5em;text-align:right;font-variant-numeric:tabular-nums">' + (v == null ? '—' : fmt(v, u)) + '</span></div>'; }).join('') + '</div>';
}
function admin(stats) {
if (!stats.length) return '<div class="bm__l"><small>aucun benchmark envoyé pour l\'instant</small></div>';
return '<div class="bm__l"><small>médiane par ' + (parMoteur ? 'moteur (la manière de tester)' : 'classe d\'appareil') + ' · survol = détail</small><button class="bm__mini" data-axe>' + (parMoteur ? 'par appareil' : 'par moteur') + '</button></div>' + barres('score', stats, 'score', '')
+ EPREUVES.map(function (e) { return barres(e.nom, stats, e.id, e.u); }).join('') + barres('gain multi-cœurs (×)', stats, 'coeursX', '');
}
function tableau(l) {
if (!l.length) return '<div class="bm__l"><small>aucun passage</small></div>';
return '<div style="overflow-x:auto"><table><tr><th>appareil</th><th>score</th><th>1 cœur</th><th>tous</th><th>mémoire</th><th>DOM</th></tr>' + l.slice(0, 40).map(function (p) { var m = p.m || p.mesures || {};
return '<tr><td>' + esc(p.nom || '') + '<br><small>' + new Date(p.quand).toLocaleDateString('fr-CH') + '</small></td><td>' + (m.score || '—') + '</td><td>' + fmt(m.cpu1) + '</td><td>' + fmt(m.cpuN) + '</td><td>' + fmt(m.memoire, 'o/s') + '</td><td>' + fmt(m.dom) + '</td></tr>'; }).join('') + '</table></div>';
}
async function lancer() {
if (enCours) return; enCours = true; courant = {}; vue = 'mesurer';
for (var i = 0; i < EPREUVES.length; i++) { var e = EPREUVES[i]; courant._etape = e.nom; rendre(); await pause();
try { courant[e.id] = await e.f(); } catch (er) { courant[e.id] = null; } }
if (courant.cpu1 && courant.cpuN) courant.coeursX = courant.cpuN / courant.cpu1;
courant.score = score(courant); delete courant._etape; enCours = false; rendre();
var app = appareil(); app.nom = nom; try { await extrasAsync(app); } catch (er) {}
var l = lire('xb:bench:passages', []); l.unshift({ quand: Date.now(), nom: (nom || app.plateforme) + ' · ' + app.moteur, m: courant }); ecrire('xb:bench:passages', l.slice(0, 50));
aEnvoyer = { version: VERSION, appareil: app, mesures: courant }; envoye = ''; rendre();
try { window.jOSPorts && jOSPorts.emit('benchmark', 'fini', { score: courant.score }); } catch (er) {}
}
container.addEventListener('click', function (ev) { var b = ev.target.closest('[data-v]'); if (b) { vue = b.getAttribute('data-v'); rendre(); return; } if (ev.target.closest('[data-go]')) lancer();
if (ev.target.closest('[data-axe]')) { parMoteur = !parMoteur; rendre(); return; }
if (ev.target.closest('[data-envoyer]') && aEnvoyer && !envoye) { envoye = '⧗ envoi…'; rendre();
fetch('/px/bench', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify(aEnvoyer) })
.then(function (r) { envoye = r.ok ? '✓ envoyé, merci' : r.status === 429 ? 'trop d\'envois, réessaie plus tard' : '✕ refusé (' + r.status + ')'; if (!r.ok) setTimeout(function () { envoye = ''; rendre(); }, 4000); rendre(); })
.catch(function () { envoye = '✕ hors ligne'; rendre(); setTimeout(function () { envoye = ''; rendre(); }, 4000); }); } });
container.addEventListener('input', function (ev) { if (ev.target.matches('[data-nom]')) { nom = ev.target.value.slice(0, 60); ecrire('xb:bench:nom', nom); } });
rendre();
return { unmount: function () { container.innerHTML = ''; } };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['benchmark'] = { manifest: { id: 'benchmark', name: 'Benchmark', icon: '⌬' }, mount: mount,
describe: function () { var l = lire('xb:bench:passages', []); return { v: 1, id: 'benchmark', title: 'Benchmark', icon: '⌬', items: [{ p: 1, kind: 'stat', label: 'dernier score', value: l[0] && l[0].m && l[0].m.score != null ? String(l[0].m.score) : '—' }] }; } };
})();
</script>