druid@mirkwood:iobuftest$ time ./a.out 0 no buffer
real 0m37.390s user 0m6.128s sys 0m4.216s druid@mirkwood:iobuftest$ time ./a.out 4096 set buffer 4096 byte(s) real 0m37.699s user 0m6.292s sys 0m4.128s druid@mirkwood:iobuftest$ time ./a.out 65536 set buffer 65536 byte(s) real 0m37.713s user 0m6.040s sys 0m3.876s
druid@mirkwood:iobuftest$ cat test.c
#include
int main(int argc, char *argv[])
{
char *fname = "out";
char s[] = "12345678901234567890";
long count = 100000000;
FILE *out;
char *buf;
out = fopen(fname, "w");
if (atol(argv[1])) {
buf = malloc(atol(argv[1]));
if (setvbuf(out, buf, _IOFBF, atol(argv[1]))) {
printf("setvbuf filed\n");
} else {
printf("set buffer %d byte(s)", atol(argv[1]));
}
} else {
printf("no buffer\n");
}
while (count--) {
fputs(s, out);
}
}
druid@mirkwood:iobuftest$ time ./a.out 0
no buffer
real 0m37.390s
user 0m6.128s
sys 0m4.216s
druid@mirkwood:iobuftest$ time ./a.out 4096
set buffer 4096 byte(s)
real 0m37.699s
user 0m6.292s
sys 0m4.128s
druid@mirkwood:iobuftest$ time ./a.out 65536
set buffer 65536 byte(s)
real 0m37.713s
user 0m6.040s
sys 0m3.876s
Reply
Leave a comment