Question

I'm trying my best to optimize the time it takes to load a webpage in my uiwebview. How can I track the number of milliseconds it takes to load it? This is more for me to see if my optimizations are working.

UPDATE: I've been using delegate methods, but the problem isn't knowing when it's finished loading, or when it began loading. I want to know how long it took from when it first began the request to when it finished loading the url (the actual time in milliseconds).

Was it helpful?

Solution

Set a property called NSDate *methodStart.

When you start loading webView:

methodStart = [NSDate date];

When finished do that:

NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart];
NSLog(@"executionTime = %f", executionTime);

Take into account that a webView usually calls webViewDidFinishLoad: a few times so you will get the NSLog a few times and the last one is the one you need.

OTHER TIPS

Log from the start of the request (also set the delegate for the UIWebView)

webView loadRequest

OR

webView loadHTMLString: baseURL:

OR

webView loadData: MIMEType: textEncodingName:   

Depending which one you are using

And log once its done via the UIWebViewDelegate method

- (void) webViewDidFinishLoad: (UIWebView*) webView
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top