1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

a urgent help need regarding GCC

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

  1. vikky1988i

    vikky1988i New Member

    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

  2. virxen

    virxen New Member

    #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 );
      return 0;
    the code is for seconds and milliseconds

Share This Page