Artifact 08f06e578c30bd17971027b8db4adc2160ba1c4b34550718cf28cd55ea21e960:
- File typeparse/exemples/crible/autres/crible.rb — 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: 454) [annotate] [blame] [check-ins using]
N=1000000 def best; b=1e18; r=nil; 5.times{ t=Process.clock_gettime(Process::CLOCK_MONOTONIC); r=yield; d=Process.clock_gettime(Process::CLOCK_MONOTONIC)-t; b=d if d<b }; [b*1000,r]; end tc,s=best{ Array.new(N,1) } tk,s2=best{ a=s.dup; a[0]=a[1]=0; i=2; while i*i<N; if a[i]==1 then j=i*i; while j<N; a[j]=0; j+=i; end; end; i+=1; end; a } tn,r=best{ s2.sum } printf("%-32s %7.1f %7.1f %7.1f %7.1f -> %d\n","Ruby 3.3 Array + boucle",tc,tk,tn,tc+tk+tn,r)