Posté par
alenvers() le 25/04/2008 à 09:52. (lien). Évalué à 7.
Effectivement, en 5 minutes, j'ai remplacé l'allocation par de la pré-allocation et les perfs sont multipliées par 10. Niveau consommation de mémoire ce n'est pas ça (mais on s'en fout ici, ça peut être réglé avec un peu plus d'effort).
Sans optimisation :
bash-3.2$ time ./binarytrees.gcc_run 16
stretch tree of depth 17 check: -1
131072 trees of depth 4 check: -131072
32768 trees of depth 6 check: -32768
8192 trees of depth 8 check: -8192
2048 trees of depth 10 check: -2048
512 trees of depth 12 check: -512
128 trees of depth 14 check: -128
32 trees of depth 16 check: -32
long lived tree of depth 16 check: -1
real 0m11.233s
user 0m8.983s
sys 0m0.000s
Avec :
bash-3.2$ /usr/bin/gcc -pipe -Wall -O3 -fomit-frame-pointer -march=pentium4 -lm binarytrees.c -o binarytrees.gcc_run
bash-3.2$ time ./binarytrees.gcc_run 16
stretch tree of depth 17 check: -1
131072 trees of depth 4 check: -131072
32768 trees of depth 6 check: -32768
8192 trees of depth 8 check: -8192
2048 trees of depth 10 check: -2048
512 trees of depth 12 check: -512
128 trees of depth 14 check: -128
32 trees of depth 16 check: -32
long lived tree of depth 16 check: -1
Re: ...
Effectivement, en 5 minutes, j'ai remplacé l'allocation par de la pré-allocation et les perfs sont multipliées par 10. Niveau consommation de mémoire ce n'est pas ça (mais on s'en fout ici, ça peut être réglé avec un peu plus d'effort).
Sans optimisation :
bash-3.2$ time ./binarytrees.gcc_run 16
stretch tree of depth 17 check: -1
131072 trees of depth 4 check: -131072
32768 trees of depth 6 check: -32768
8192 trees of depth 8 check: -8192
2048 trees of depth 10 check: -2048
512 trees of depth 12 check: -512
128 trees of depth 14 check: -128
32 trees of depth 16 check: -32
long lived tree of depth 16 check: -1
real 0m11.233s
user 0m8.983s
sys 0m0.000s
Avec :
bash-3.2$ /usr/bin/gcc -pipe -Wall -O3 -fomit-frame-pointer -march=pentium4 -lm binarytrees.c -o binarytrees.gcc_run
bash-3.2$ time ./binarytrees.gcc_run 16
stretch tree of depth 17 check: -1
131072 trees of depth 4 check: -131072
32768 trees of depth 6 check: -32768
8192 trees of depth 8 check: -8192
2048 trees of depth 10 check: -2048
512 trees of depth 12 check: -512
128 trees of depth 14 check: -128
32 trees of depth 16 check: -32
long lived tree of depth 16 check: -1
real 0m1.235s
user 0m0.843s
sys 0m0.140s
void* mem_chunks = NULL;
char* mem_pos = NULL;
char* mem_chunks_nbr = 0;
void
*my_malloc(size_t NBYTES)
{
char* temp;
if (! mem_chunks)
mem_pos = mem_chunks = malloc(NBYTES * 100000000);
temp = mem_pos;
mem_pos += NBYTES;
mem_chunks_nbr++;
return temp;
}
void
*my_free(void *APTR)
{
if (! --mem_chunks_nbr) {
free(mem_chunks);
mem_chunks = NULL;
}
return NULL;
}
[ Répondre ]