[C Language] creating 10 Gb files within 1 s

Source: Internet
Author: User

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
     
      

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.