Measuring time in nanosec in C programming

View previous topic View next topic Go down

Measuring time in nanosec in C programming

Post by BIT0122-Amit on Tue Aug 04, 2009 2:21 pm

Want to get the details on every functionality of time.h header file? Wink

Click here

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Re: Measuring time in nanosec in C programming

Post by BIT0122-Amit on Sat Aug 08, 2009 3:23 am

Guys, if you are unsure about how to use tv_nsec, go to this
Link

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Re: Measuring time in nanosec in C programming

Post by BIT0122-Amit on Sun Aug 09, 2009 3:07 am

those who are too lazy to get the code from the above link:

Code:
#include <iostream>
#include <time.h>
using namespace std;
 
timespec diff(timespec start, timespec end);
 
int main()
{
   timespec time1, time2;
   int temp;
   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
      //Do your fancy complex calculation here.

   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
   cout<<diff(time1,time2).tv_sec<<":"<<diff(time1,time2).tv_nsec<<endl;
   return 0;
}
 
timespec diff(timespec start, timespec end)
{
   timespec temp;
   if ((end.tv_nsec-start.tv_nsec)<0) {
      temp.tv_sec = end.tv_sec-start.tv_sec-1;
      temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
   } else {
      temp.tv_sec = end.tv_sec-start.tv_sec;
      temp.tv_nsec = end.tv_nsec-start.tv_nsec;
   }
   return temp;
}

don't forget to compile it using the -lrt switch


And those who doesn't even know how to use -lrt swicth....
My sympathies for you Rolling Eyes

Code:
g++ filename -o file -lrt

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Re: Measuring time in nanosec in C programming

Post by BIT0115-Efat on Mon Aug 10, 2009 1:09 am

thanx 2 dear frndz.......specially to AMIT gullu.......AMIT na thakle to amra Pagol hoia jaitam
avatar
BIT0115-Efat
Service Release
Service Release

Course(s) :
  • BIT

Blood Group : O+
Posts : 779
Points : 1120

View user profile

Back to top Go down

Re: Measuring time in nanosec in C programming

Post by BIT0108-mostafa on Tue Aug 11, 2009 5:18 pm

thanks ami
keep going
avatar
BIT0108-mostafa
Release Candidate
Release Candidate

Course(s) :
  • BIT

Blood Group : O+
Posts : 118
Points : 184

View user profile

Back to top Go down

Re: Measuring time in nanosec in C programming

Post by BIT0111-muctadir on Thu Aug 13, 2009 6:09 am

do not fear,
amit is here...
avatar
BIT0111-muctadir
Expert
Expert

Course(s) :
  • BIT

Blood Group : B+
Posts : 233
Points : 395

View user profile

Back to top Go down

Re: Measuring time in nanosec in C programming

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum