title: How to obtain the execution time of a function in C/C++
body: <p>I have a function which can generate 10000 random numbers and write them in a file.</p>
  
  <pre><code>void generator(char filename[])              
  {
      int i;
      int n;
      FILE* fp;
      if((fp=fopen(filename,"w+"))==NULL)
      {
          printf("Fail creating file！");
      }
      srand((unsigned)time(NULL));
      for(i=0;i&lt;10000;i++)
      {
          n=rand()%10000;
          fprintf(fp,"%d ",n);
      }
      fclose(fp);
  }
  </code></pre>
  
  <p>How can I get the execution time of this function using C/C++ ?</p>