Calculate the time difference using difftime yields unexpected result
Calculate the time difference using difftime yields unexpected result
- Subject: Calculate the time difference using difftime yields unexpected result
- From: Alexander Hartner <email@hidden>
- Date: Thu, 8 Mar 2007 01:28:25 +0000
I am trying to calculate the time it took for a certain task, so I
tried to use difftime, as shown in the example below. Yet when I try
to use difftime the result is much larger then I would expect. I also
tried simply subtracting the to time measurements from each other and
get a much better result. The man page says that I should get the
difference in seconds, which is exactly what I am looking for.
Here is the example :
time_t startTime = time(nil);
...do some work here
time_t endTime = time(nil);
NSLog(@"START TIME : %s",ctime(&startTime));
NSLog(@"END TIME : %s",ctime(&endTime));
NSLog(@"PERIOD : %d",(endTime-startTime));
double period = difftime(endTime,startTime);
NSLog(@"PERIOD DIFF: %d",period);
OUTPUT:
2007-03-08 01:23:21.497 Address Book 4 Everyone[8349] START TIME :
Thu Mar 8 01:23:14 2007
2007-03-08 01:23:21.497 Address Book 4 Everyone[8349] END TIME :
Thu Mar 8 01:23:21 2007
2007-03-08 01:23:21.497 Address Book 4 Everyone[8349] PERIOD : 7
2007-03-08 01:23:21.497 Address Book 4 Everyone[8349] PERIOD DIFF:
1075576832Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden