IOS webpage load time measurement

I searched a lot, but couldn't find a way to measure web page load time in iOS. In the application, I want to show a specific page load time. Is this possible with iOS sdk or third-party sdk?

thanks

+4
source share
2 answers

You can load the URL request and use NSDate to find out how much time has passed ... suggests that you are using a UIWebView to display your page to measure load time, I would capture the time when the URL was requested, and then to delegate methods - (void) webViewDidFinishLoad: (UIWebView *) webView registers the time again and takes a value, for example

//lets say this is where you load the request and you already have your webview set up with a delegate -(void)loadRequest { [webView loadRequest:yourRequest]; startDate=[NSDate date] } //this is the delegate call back for UIWebView - (void)webViewDidFinishLoad:(UIWebView *)webView { NSDate *endDate=[NSDate date]; double ellapsedSeconds= [endDate timeIntervalSinceDate:startDate]; } 

If you want to do this without a UIWebView, you can just use NSURLRequest / NSURLConnection ... you can do the following (I will do it synchronously, you can also do it async)

  NSDate *start=[NSDate date]; NSURLRequest *r= [[ [NSURLRequest alloc] initWithURL:url] autorelease]; NSData *response= [NSURLConnection sendSynchronousRequest:r returningResponse:nil error:nil]; NSDate *end=[NSDate date]; double ellapsedSeconds= [start timeIntervalSinceDate:end]; 
+3
source

Assuming you are working with a UIWebView , you can set its delegate and specify the time in the delegate method -webViewDidFinishLoad: The difference between this time and an earlier call to the webview -loadRequest: method should give you load time.

0
source

Source: https://habr.com/ru/post/1369244/


All Articles