开发者

How to perform a latency test in iPhone

开发者 https://www.devze.com 2023-02-08 17:15 出处:网络
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开发者_StackOver

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号