0

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).

KingPolygon
  • 4,753
  • 7
  • 43
  • 72
  • check it https://developer.apple.com/library/ios/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIWebViewDelegate – Tirth Jan 06 '14 at 00:38

2 Answers2

1

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.

Refael.S
  • 1,634
  • 1
  • 12
  • 22
-1

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
Raymond Brion
  • 332
  • 1
  • 10