如何在 iPhone 中执行延迟测试

发布于 2024-10-15 08:44:10 字数 134 浏览 1 评论 0原文

我想对我的 iPhone 应用程序中的不同 url 执行延迟测试,一种方法是对 url 发出异步请求,并根据控件到达 connectionDidFinish 委托的时间来测量持续时间,这是正确的方法吗或者 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 upon when the control reaches in connectionDidFinish delegate, is this the correct approach or some alternatives available in iPhone to measure latency time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剧终人散尽 2024-10-22 08:44:10

我不确定你如何定义延迟。请参阅wiki 文章以获得一些说明。

我会分析响应时间来了解网络延迟,这在移动连接中非常有趣。我在我开发的应用程序之一中使用了这种方法:

- (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);
    ...
}

限制带宽用于模拟器测试可能是非常有帮助。

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.

不语却知心 2024-10-22 08:44:10

将 Mac 的 Airport 共享到 iPhone(将其桥接到以太网)。然后在Mac上使用tcpdump捕获网络流量,使用Wireshark查看pcap,这将为您提供网络延迟的最佳视图。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文