26Fermer28
GodzilLe 16/11/2009 à 16:23
Petit test simple :
gdz@confucius ~/tmp $ ls test*.c
test1.c  test2.c  test3.c
gdz@confucius ~/tmp $ cat test*.c
/* test1.c */
#include <stdio.h>


int main(int argc, char *argv[])
{
   unsigned long i, j;
   for(i = 0; i < 65535; i++)
   {	
      printf(".");
   }
}
/*
 * vim: textwidth=79 ts=3 sts=3 expandtab
 */
/* test2.c */
#include <stdio.h>


int main(int argc, char *argv[])
{
   unsigned long i, j;
   for(i = 0; i < 65535; i++)
   {	
      printf(".");
      fflush(stdout);
   }
}
/*
 * vim: textwidth=79 ts=3 sts=3 expandtab
 */
 /* test3.c */
#include <stdio.h>


int main(int argc, char *argv[])
{
   unsigned long i, j;
   for(i = 0; i < 65535; i++)
   {	
      //printf(".");
   }
}
/*
 * vim: textwidth=79 ts=3 sts=3 expandtab
 */
gdz@confucius ~/tmp $ gcc test1.c -o test1
gdz@confucius ~/tmp $ gcc test2.c -o test2
gdz@confucius ~/tmp $ gcc test3.c -o test3
gdz@confucius ~/tmp $ time ./test1
...... [snap] ....
real	0m0.537s
user	0m0.008s
sys	0m0.000s
gdz@confucius ~/tmp $ time ./test2
...... [snap] ....
real	0m0.670s
user	0m0.012s
sys	0m0.104s
yep@confucius ~/tmp $ time ./test3

real	0m0.003s
user	0m0.000s
sys	0m0.000s

Le volume a afficher n'est pas enorme dans ce cas, et la console flush automatiquement quand le buffer dépasse une certaine taille, en plus du moment ou il rencontre un "\n", mais la différence de temps d'execution est plus que notable