-6

how i calculate real time in a program of c ....

__________________________start=clock(); ----------------------------end=clock();

diff=end-start;

start=124682129.0000000 end =124682129.0000000 result value of diff is 0.0000000000000000000000

i am sorting an array i want to calculate time before sort and end of sort in gcc compiler ......

how i can calculate these times? real time execution time

  • 1
    possible duplicate of [Calculating elapsed time in a C program in milliseconds](http://stackoverflow.com/questions/1468596/calculating-elapsed-time-in-a-c-program-in-milliseconds) – CaringDev Sep 20 '15 at 08:08
  • Did you try to google it first? it's a pretty common question with many answers online, you should ask here only when you encounter a problem. – Tamir Vered Sep 20 '15 at 08:12

2 Answers2

1

If you want to get the execution time of your program, you can do this:

//some code
#include <time.h>

int main () { 
    double seconds;
    time_t started=time(NULL);
    RunSomeFunc();
    seconds=difftime(time(NULL),started);
    //more code
}

Here you're measuring the execution time of RunSomeFunc.


Docs

Community
  • 1
  • 1
ForceBru
  • 43,482
  • 10
  • 63
  • 98
0

simple program to print time in C

/* localtime example */
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "Current local time and date: %s", asctime (timeinfo) );

  return 0;
}
Nitin Tripathi
  • 1,224
  • 7
  • 17