Artifact 3058b48e011175e1b3a6df200ee593d7f16479f35dfd52bf1af9fd4ceedee563:
- File typeparse/exemples/crible/autres/crible.c — 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: 654) [annotate] [blame] [check-ins using]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define N 1000000 static double now(){struct timespec t;clock_gettime(CLOCK_MONOTONIC,&t);return t.tv_sec*1e3+t.tv_nsec/1e6;} int main(){double bc=1e9,bk=1e9,bn=1e9;long r=0; for(int it=0;it<5;it++){double t=now();unsigned char*s=malloc(N);memset(s,1,N);double t1=now(); s[0]=s[1]=0;for(long i=2;i*i<N;i++)if(s[i])for(long j=i*i;j<N;j+=i)s[j]=0;double t2=now(); long c=0;for(long i=0;i<N;i++)c+=s[i];double t3=now();r=c; if(t1-t<bc)bc=t1-t;if(t2-t1<bk)bk=t2-t1;if(t3-t2<bn)bn=t3-t2;free(s);} printf("%-32s %7.1f %7.1f %7.1f %7.1f -> %ld\n","C (gcc -O2)",bc,bk,bn,bc+bk+bn,r);}