Assuming you are running in a multithreaded environment, answering your question would require a lot more information than you are giving us. Suffice to say, there is no guarantee that your sleeping thread will run "calling some method" exactly 200ms later, because that depends on what your other threads are doing.
Sleeping a thread like your example is generally considered a bad idea. Here's another way to accomplish what I think you are trying to do, but with ... better citizenship.
- (void)loopIfNeeded
{
if (...condition...) {
// do something
// ... and then call -someMethod ~200ms later
[self performSelector:@selector(someMethod) withObject:nil afterDelay:0.2];
}
}
- (void)someMethod
{
// whatever some method does
[self loopIfNeeded]; // continue loop
}
Finally, some observations:
-[NSDate timeIntervalSince1970]
returns seconds (and fractions thereof, docs here), not milliseconds (although it has ms precision).For timing, I find
CFAbsoluteTime
to be lighter weight:CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); // do your thing CFAbsoluteTime end = CFAbsoluteTimeGetCurrent(); CFTimeInterval elapsed = start - end; // or just NSLog(@"elapsed %f", start - end);