stdio performance in tango, stdlib, and perl

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sat Mar 24 07:53:59 PDT 2007


torhu wrote:
> torhu wrote:
>> ---
>> /* C test w/malloc and free */
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main() {
>>
>>     char *buf = malloc(1000);
>>     while (fgets(buf, sizeof(buf), stdin)) {
>>        fputs(buf, stdout);
>>        free(buf);
>>        buf = malloc(1000);
>>     }
>>     free(buf);
>>     return 0;
>> ---
> 
> Whoops, can anyone spot the bug?  When I fixed it, the time it took to 
> run my test went down from about 23 to about 3 seconds.

I'm guessing the fact that sizeof(buf) != 1000 ?



More information about the Digitalmars-d mailing list