ios – NSDate timeIntervalSinceNow seems to be giving inflated value

0
56

[ad_1]

In my Obj C code, I want to know the time taken by a completion handler to return result. This is how I measure the duration:

NSDate *start = [NSDate date];

[_client asyncCallWithInput:@"INPUT" completionHandler:^(Output output, NSError * _Nullable error) {
    [recordMetricWithDuration fabs([start timeIntervalSinceNow]];
}]

But when I look at the recorded values for this I see them in the order of 1000s and around 4k minimum. This is obviously incorrect because 4k seconds is more than an hour and I know the function does not take that long. (timeIntervalSinceNow returns a NSTimeInterval which “is always specified in seconds”)

Elsewhere in the code I see this used, which seems to be giving correct value.

CFTimeInterval start = CACurrentMediaTime();
...
CFTimeInterval duration = CACurrentMediaTime() - start;

What am I missing? From the docs for [NSDate date] “Creates and returns a new date object set to the current date and time.”, so I should be getting correct value too.

Edit:

I just realized that the place where I record duration needs the duration to be of type CFTimeInterval but I am passing it NSTimeInterval. Maybe that is causing an issue?

[ad_2]