Re: Elapsed time of a thread
Re: Elapsed time of a thread
- Subject: Re: Elapsed time of a thread
- From: "Alastair J.Houghton" <email@hidden>
- Date: Sat, 4 Oct 2003 13:51:59 +0100
On Friday, October 3, 2003, at 07:33 pm, Dave Keck wrote:
you can use an NSDate object at the beginning of the thread, and at
the end you can access the NSDate instance's timeIntervalSinceNow
method:
At the beginning:
NSDate *date = [NSDate date];
At the end:
NSLog(@"%f", [date timeIntervalSinceDate]);
This will print the time in seconds that the thread ran for.
Well, it doesn't actually quite do what you just said; rather, it
prints the time in seconds that has elapsed since the thread started
running. To illustrate the difference, imagine you have, on a
single-CPU system, two threads of equal priority, both of which are
processor-bound. The machine isn't otherwise busy, so both threads
will get approximately 50% of the CPU. If the pair of them complete
after ten seconds, then the NSLog() call will display "10.0" in both
threads, however each thread only ran for a total of *five* seconds.
If all you want is elapsed real time, then this method will be fine.
If you were hoping for something else, then AFAIK there isn't a way to
get that information for threads, although you can certainly obtain it
for processes using the BSD function getrusage().
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.