Today, the senior student asked me to write a program for him to create a 10 Gb file within 1 s (he is doing big data ). I just started to use the general practice. It was a waste of time. Later I searched for it online for a long time and saw a promising program, but I didn't understand it very well, here I just want to show you the program. I don't know how to create such a large file!
In fact, this is the difference between fputc and fwrite functions, the time used by the two is very different!
Use fputc for execution: (about 30 s for 1 GB)
Figure 1 fputc execution result
Fwrite execution result:
Figure 2 fwrite execution result
It can be seen that fwrite is basically completed immediately!
#include
#include
#include
#include
#pragma comment( lib,"winmm.lib" )void main(){unsigned long i, block,filesize;char type;FILE *fd;char filename[64];fpos_t pos;DWORD s_time,p_time;printf("Input your file name:");scanf("%s",filename);fd = fopen(filename,"wb+");if(fd == NULL){perror("Create file Fail:");return ;}setsize:printf("Input file size:");scanf("%d%c",&filesize,&type);s_time = clock();fgetpos (fd,&pos);switch(type){case 'K':case 'k':block = 0x400; break;case 'M':case 'm':block = 0x100000;break;case 'G':case 'g':block = 0x40000000;for(i=0; i