Artifact def3fa2e6645551bde3c18e1d41870618412494eee398abe8e8902c419383017:
- File typeparse/exemples/crible/autres/crible.js — part of check-in [c8a247a331] at 2026-11-26 10:32:15 on branch tip-764_tcl90 — - A strided slice of a compact list filled with a single value is validated and encoded once, then copied cell to cell (TclCompactFillFrom). Sieve, 10^6 bytes: 99 -> 2.2 ms; 9 ms total. - exemples/crible: comparison with C, JavaScript, Python, PHP, Ruby, Perl - type repeat T N ?value?: a list of T made of N times the value (zero by default), in cells without an intermediate list (one million bytes: 0.1 ms); test t131 - direct sum of s + $v over integer cells (8, 16, 32 bits) when no partial sum can exceed 64 bits; test t132 (sieve, 10^6 bytes: counting 2.8 -> 0.2 ms, 2.5 ms total) (user: Florentis, size: 764) [annotate] [blame] [check-ins using]
const N=1000000; function best(f,a){let b=1e18,r;for(let i=0;i<5;i++){const t=process.hrtime.bigint();r=f(a);const d=Number(process.hrtime.bigint()-t)/1e6;if(d<b)b=d;}return [b,r];} function c(){return new Uint8Array(N).fill(1);} function k(s0){const s=s0.slice();s[0]=s[1]=0;for(let i=2;i*i<N;i++)if(s[i])for(let j=i*i;j<N;j+=i)s[j]=0;return s;} function n(s){let c=0;for(let i=0;i<s.length;i++)c+=s[i];return c;} function c2(){return new Array(N).fill(1);} for (const [nom,C] of [["JavaScript (Node) Uint8Array",c],["JavaScript (Node) Array",c2]]){ let [tc,s]=best(C);let [tk,s2]=best(k,s);let [tn,r]=best(n,s2); console.log(nom.padEnd(32),tc.toFixed(1).padStart(7),tk.toFixed(1).padStart(7),tn.toFixed(1).padStart(7),(tc+tk+tn).toFixed(1).padStart(7),"->",r);}