Streetboy
Streetboy

Reputation: 4401

Calculate request and response execution time

Is it possible to calculate request and response time to server ?

For example request was 1 sec. response 2 sec. ?

Generally what takes more to send/receive request or for server to return response ?

Maybe they always take same time and if it lasted for 3 sec. to return data to app, i can 3/2 = 1.5 and think that request and response lasted for 1.5 sec. ?

Thank you

Upvotes: 2

Views: 3529

Answers (2)

Wolverine
Wolverine

Reputation: 4329

For requesting and getting response, i assume you have created some Method

so this may help

NSDate *Start_Time_OF_Method = [NSDate date];

/* ... Do whatever you need to do. for example Your Request/Response kind of coading ... */

NSDate *Finish_Time_OF_Method = [NSDate date];

NSTimeInterval executionTime = [Finish_Time_OF_Method timeIntervalSinceDate:Start_Time_OF_Method];

NSLog(@"executionTime = %f", executionTime); 

Upvotes: 2

Wim Haanstra
Wim Haanstra

Reputation: 5998

Assuming you are using a NSURLConnection to make the request to the server, the NSURLConnectionDelegate supports quite a lot of delegate methods which can help you here.

Take a look at the documentation: https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html

When you override those delegate methods I think you can get the information you are looking for. Just make sure you start and stop the timers at the right moment and you will be all set.

Upvotes: 1

Related Questions