How to perform a latency test in iPhone
I would like to perform a latency test with respect to different urls in my iPhone app, an approach would be to make an async request for an url and measure the time duration based upo开发者_StackOverflow中文版n when the control reaches in connectionDidFinish delegate, is this the correct approach or some alternatives available in iPhone to measure latency time?
I am not sure how you define latency. Look at the wiki article for some clarification.
I'd profile for the response time to get a picture of the network lag, very interesting in mobile connections. I am using this approach in one of the apps I've developed:
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
...
self.reqStart = [NSDate date];
self.url = [[request URL] absoluteString];
NSLog(@"--> Requesting : %@", url);
...
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse
{
NSLog(@"<-- Response time %fs : %@", [[NSDate date] timeIntervalSinceDate:reqStart], url);
...
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"<== Request time %fs : %@", [[NSDate date] timeIntervalSinceDate:reqStart], url);
...
}
Throttling bandwidth for simulator testing could be very helpful.
Share your Mac's Airport to your iPhone (bridge it to Ethernet). Then use tcpdump on the Mac to capture the network traffic, using Wireshark to view the pcap, this will give you the best view of network latency.
精彩评论