Si, quella
@all
Premetto che le statistiche seguenti sono relative solo alle 3 migliori funzioni.
La terza l'ho corretta in questa forma perché includeva altri valori in testa e coda:
Codice: Seleziona tutto
int isvoc (char c)
{
int i = (toupper(c)-'A');
return (i & 0xe0)? 0:(0x104111UL & (1<<i));
}
Ho usato
perf come profiler, con l'opzione
--sync che viene eseguita prima di ogni ri-esecuzione.
Ho inoltre creato vari livelli di TEST, sia sul l'intero charset, sia usando testi campione (lorem ipsum, ecc).
Input static, output quasi nullo (solo qualche byte di controllo)
Legenda:
Codice: Seleziona tutto
max@studio:~/tmp/foo$ ll claudio max MAW
lrwxrwxrwx 1 max max 1 dic 21 11:56 claudio -> 2
lrwxrwxrwx 1 max max 1 dic 21 11:56 MAW -> 3
lrwxrwxrwx 1 max max 1 dic 21 11:56 max -> 1
max@studio:~/tmp/foo$
max@studio:~/tmp/foo$ alias perfstat
alias perfstat='perf stat'
1 TEST x CHARSET - 10,000 ri-esecuzioni
Codice: Seleziona tutto
max@studio:~/tmp/foo$ CFLAGS=-DTEST1
max@studio:~/tmp/foo$ export CFLAGS && c 1 2 3
cc -DTEST1 1.c -o 1: OK
cc -DTEST1 2.c -o 2: OK
cc -DTEST1 3.c -o 3: OK
max@studio:~/tmp/foo$
Codice: Seleziona tutto
max@studio:~/tmp/foo$ perfstat -S -r 10000 ./claudio
Performance counter stats for './claudio' (10000 runs):
0,246306 task-clock # 0,578 CPUs utilized ( +- 0,33% )
0 context-switches # 0,000 M/sec ( +- 7,85% )
0 CPU-migrations # 0,000 M/sec ( +- 6,06% )
107 page-faults # 0,433 M/sec ( +- 0,00% )
708350 cycles # 2,876 GHz ( +- 0,13% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
403021 instructions # 0,57 insns per cycle ( +- 0,02% )
87688 branches # 356,012 M/sec ( +- 0,02% )
3125 branch-misses # 3,56% of all branches ( +- 0,07% )
0,000425872 seconds time elapsed ( +- 0,43% )
max@studio:~/tmp/foo$ perfstat -S -r 10000 ./max
Performance counter stats for './max' (10000 runs):
0,246089 task-clock # 0,579 CPUs utilized ( +- 0,29% )
0 context-switches # 0,000 M/sec ( +- 8,62% )
0 CPU-migrations # 0,000 M/sec ( +- 6,24% )
110 page-faults # 0,446 M/sec ( +- 0,00% )
723199 cycles # 2,939 GHz ( +- 0,12% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
400389 instructions # 0,55 insns per cycle ( +- 0,02% )
90140 branches # 366,291 M/sec ( +- 0,02% )
3176 branch-misses # 3,52% of all branches ( +- 0,07% )
0,000425189 seconds time elapsed ( +- 0,41% )
max@studio:~/tmp/foo$ perfstat -S -r 10000 ./MAW
Performance counter stats for './MAW' (10000 runs):
0,245179 task-clock # 0,568 CPUs utilized ( +- 0,27% )
0 context-switches # 0,000 M/sec ( +- 6,84% )
0 CPU-migrations # 0,000 M/sec ( +- 6,22% )
110 page-faults # 0,448 M/sec ( +- 0,00% )
746863 cycles # 3,046 GHz ( +- 0,15% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
399899 instructions # 0,54 insns per cycle ( +- 0,02% )
89901 branches # 366,676 M/sec ( +- 0,02% )
3149 branch-misses # 3,50% of all branches ( +- 0,07% )
0,000431358 seconds time elapsed ( +- 0,50% )
max@studio:~/tmp/foo$
2 TEST LOREM IPSUM - 1,000 ri-esecuzioni
Codice: Seleziona tutto
max@studio:~/tmp/foo$ wc text.txt
31 1215 8296 text.txt
max@studio:~/tmp/foo$ export CFLAGS=-DTEST3 && c 1 2 3
cc -DTEST3 1.c -o 1: OK
cc -DTEST3 2.c -o 2: OK
cc -DTEST3 3.c -o 3: OK
Codice: Seleziona tutto
max@studio:~/tmp/foo$ perfstat -S -r 1000 ./claudio > /dev/null
Performance counter stats for './claudio' (1000 runs):
0,392835 task-clock # 0,687 CPUs utilized ( +- 1,28% )
0 context-switches # 0,000 M/sec ( +- 21,07% )
0 CPU-migrations # 0,000 M/sec ( +- 17,95% )
128 page-faults # 0,325 M/sec ( +- 0,01% )
1109991 cycles # 2,826 GHz ( +- 0,27% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
1059855 instructions # 0,95 insns per cycle ( +- 0,02% )
127127 branches # 323,615 M/sec ( +- 0,04% )
5651 branch-misses # 4,44% of all branches ( +- 0,12% )
0,000571406 seconds time elapsed ( +- 1,31% )
max@studio:~/tmp/foo$ perfstat -S -r 1000 ./max > /dev/null
Performance counter stats for './max' (1000 runs):
0,373758 task-clock # 0,690 CPUs utilized ( +- 1,04% )
0 context-switches # 0,000 M/sec ( +- 18,18% )
0 CPU-migrations # 0,000 M/sec ( +- 16,92% )
131 page-faults # 0,350 M/sec ( +- 0,01% )
1108049 cycles # 2,965 GHz ( +- 0,31% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
885881 instructions # 0,80 insns per cycle ( +- 0,03% )
182492 branches # 488,261 M/sec ( +- 0,03% )
6305 branch-misses # 3,46% of all branches ( +- 0,10% )
0,000541572 seconds time elapsed ( +- 1,02% )
max@studio:~/tmp/foo$ perfstat -S -r 1000 ./MAW > /dev/null
Performance counter stats for './MAW' (1000 runs):
0,361012 task-clock # 0,677 CPUs utilized ( +- 0,76% )
0 context-switches # 0,000 M/sec ( +- 14,87% )
0 CPU-migrations # 0,000 M/sec ( +- 17,13% )
131 page-faults # 0,362 M/sec ( +- 0,01% )
1116083 cycles # 3,092 GHz ( +- 0,35% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
887663 instructions # 0,80 insns per cycle ( +- 0,02% )
175564 branches # 486,311 M/sec ( +- 0,03% )
6279 branch-misses # 3,58% of all branches ( +- 0,11% )
0,000533325 seconds time elapsed ( +- 1,34% )
max@studio:~/tmp/foo$
EDIT:
vbextreme ha scritto:
Ho eseguito un test rapido sulla velocità, riempiendo un vettore di 1024 valori ripetuti nel range da 0-255, in sostanza ho eseguito la funzione "isvoc" * 4 volte su tutti i valori ascii. solo con -O2
Ecco il risultato del tempo clompessivo che andrebbe diviso per 1024 per trovare il singolo tempo:
[...]
Presta attenzione alle ottimizzazioni del compilatore. Una semplice chiamata di una funzione che non fa niente viene tolta. Puoi controllare disassemblando il codice