Artifact 0b85d621ec54abd62badca25e0b51e84e548690e61a8ae564402041a55496858:
- File typeparse/exemples/crible/autres/crible.pl — 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: 475) [annotate] [blame] [check-ins using]
use Time::HiRes qw(time); my $N=1000000; sub best{my $f=shift;my $b=1e18;my $r;for(1..5){my $t=time;$r=$f->();my $d=time-$t;$b=$d if $d<$b}return($b*1000,$r)} my ($tc,$s)=best(sub{[(1)x$N]}); my ($tk,$s2)=best(sub{my @a=@$s;$a[0]=$a[1]=0;for(my $i=2;$i*$i<$N;$i++){if($a[$i]){for(my $j=$i*$i;$j<$N;$j+=$i){$a[$j]=0}}}\@a}); my ($tn,$r)=best(sub{my $c=0;$c+=$_ for @$s2;$c}); printf("%-32s %7.1f %7.1f %7.1f %7.1f -> %d\n","Perl tableau + boucle",$tc,$tk,$tn,$tc+$tk+$tn,$r);