1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

a urgent help need regarding GCC

Discussion in 'C' started by vikky1988i, Apr 2, 2010.

  1. vikky1988i

    vikky1988i New Member

    Joined:
    Apr 1, 2010
    Messages:
    25
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Mainframes Admin. @ I | Nautix Technologies
    Location:
    chennai , Tamil Nadu ,INDIA
    I am Vignesh back to go4expert forums.... my login has been removed due to spam messages :)

    i have registered back with different login id :)
    i have a doubt regarding GCC.... how can i get the complete execution time in milliseconds and microseconds for a program executed through GCC.... is there any function in gcc????


    let me know soon :)

    thanks in adavnce

    S.R.Vignesh
     
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    Code:
    #include <stdio.h>
    #include <time.h>
          
    int main(){
      clock_t start = clock();
      printf("\ncalculating time elapsed,please wait!\n");
      /* Code you want timed here */
      for (int i=0;i<30000;i++)
           for (int j=0;j<30000;j++){}
      /*end timed code*/
      double timeElapsedInseconds=((double)clock() - start) / CLOCKS_PER_SEC;
      long timeElapsedInmilliseconds=(long)(1000*((double)clock() - start) / CLOCKS_PER_SEC);
      printf("Time elapsed: %f seconds\n",timeElapsedInseconds );
      printf("Time elapsed: %ld milliseconds\n",timeElapsedInmilliseconds );
      getchar();
      return 0;
    }
    
    the code is for seconds and milliseconds
     

Share This Page