AnsweredAssumed Answered

fread and fwrite are very slow

Question asked by pereira on Jan 25, 2017
Latest reply on Feb 3, 2017 by Kader.M

Hi.

Here is my code:

 

#include <stdio.h>

#define FRM_SZ         128

int input_stream[FRM_SZ];
int output_stream[FRM_SZ];
    
int main(void) {    
    int i;
    FILE* input_file        = fopen("../In", "rb");
    FILE* output_file       = fopen("../Out", "wb");
    
    if(input_file == NULL) {
        return 1;
    }
    
    while(1) {
        fread(input_stream, sizeof(int), FRM_SZ, input_file);
        if(feof(input_file))     break;
        
        Process(input_stream, output_stream, FRM_SZ);
        
        fwrite(output_stream, sizeof(int), FRM_SZ, output_file);        
    }

 

    if(input_file != NULL)         fclose(input_file);
    if(output_file != NULL)        fclose(output_file);

 

    return 0;
}

 

The critical parts are in red, and make my program being very slow (like hours to process a short input file) with ADSP-214xx Simulator.

Is there any way I could accelerate the processing? I didn't expect these functions being that slow.

 

Regards.

Outcomes