Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   a urgent help need regarding GCC (http://www.go4expert.com/forums/urgent-help-regarding-gcc-t21628/)

vikky1988i 2Apr2010 10:05

a urgent help need regarding GCC
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


virxen 2Apr2010 13:50

Re: a urgent help need regarding GCC

#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

All times are GMT +5.5. The time now is 10:29.