Using fprintf is a huge time receiver, especially for registering R / T. Record in binary format and write a utility to print it later.
Instead:
fprintf(file,"%.2f %.2f %.2f",data1,data2,data3);
make:
fwrite(&data1,sizeof(double),1,file); fwrite(&data2,sizeof(double),1,file); fwrite(&data3,sizeof(double),1,file);
Even better:
struct data { double data1; double data2; double data3; time_t event_time; ... }; struct data data; fwrite(&data,sizeof(struct data),1,file);
If it is still too slow, add the structure to the ring queue and select a separate thread.
If writing to a disk cannot keep up with binary data [now], support the call queue and unload the queue after opening if you find a fatal error
Also, consider using mmap to access the file when recording. See My answer [with benchmarks] here: read in turn in the most efficient way * specific platform *
source share