Permalink
Browse files

Also test JS execution speeds in *WebView.

  • Loading branch information...
mihaip committed Aug 7, 2014
1 parent cfce3ae commit f678aac4a7fdd3d7b4ea4ce457e2723c9a645504
@@ -5,6 +5,7 @@
#import <mach/mach_time.h>
enum Mechanism {
// UIWebView mechanisms
LocationHref = 0,
LocationHash,
LinkClick,
@@ -13,7 +14,14 @@
XhrAsync,
CookieChange,
JavaScriptCore,
// WKWebView mechanisms
WKWebViewHandler,
// Not actual full mechanisms, but just ways of measuring the native -> web function call time.
UIWebViewExecuteJs,
WKWebViewExecuteJs,
kNumMechanisms
};
@@ -157,6 +165,13 @@ -(void)startIteration {
} else {
[self endIteration:0];
}
} else if (mechanism == UIWebViewExecuteJs) {
[_uiWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"ping(%d, '%qu')", mechanism, start]];
[self endIteration:mach_absolute_time() - start];
} else if (mechanism == WKWebViewExecuteJs) {
[_wkWebView evaluateJavaScript:[NSString stringWithFormat:@"ping(%d, '%qu')", mechanism, start] completionHandler:^(id result, NSError *error) {
[self endIteration:mach_absolute_time() - start];
}];
} else {
[_uiWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"ping(%d, '%qu')", mechanism, start]];
}
@@ -201,7 +216,11 @@ -(void)showBenchmarkResults {
case XhrAsync: name = @"XHR async "; break;
case CookieChange: name = @"document.cookie "; break;
case JavaScriptCore: name = @"JavaScriptCore "; break;
case WKWebViewHandler: name = @"WKWebViewHandler"; break;
case WKWebViewHandler: name = @"\nWKWebViewHandler"; break;
case UIWebViewExecuteJs: name = @"\nUI…ExecuteJs "; break;
case WKWebViewExecuteJs: name = @"WK…ExecuteJs "; break;
}
MechanismTiming *timing = &_mechanismTimings[i];
double averageMs = [self machTimeToMs:timing->sum]/(double)kNumIterationsPerMechanisms;
@@ -6,7 +6,8 @@ var Mechanism = {
XhrSync: 4,
XhrAsync: 5,
CookieChange: 6,
JavaScriptCore: 7
JavaScriptCore: 7,
UIWebViewExecuteJs: 9
};
// The link does not need to be appended to the document, that avoids triggering
@@ -49,6 +50,8 @@ function ping(mechanism, startTime) {
case Mechanism.JavaScriptCore:
viewController.pong(startTime);
break;
case Mechanism.UIWebViewExecuteJs:
return startTime;
}
}
@@ -1,5 +1,6 @@
var Mechanism = {
WkWebViewHandler: 8
WkWebViewHandler: 8,
WKWebViewExecuteJs: 10
};
var pingCount = 0;
@@ -9,6 +10,9 @@ function ping(mechanism, startTime) {
case Mechanism.WkWebViewHandler:
window.webkit.messageHandlers.pong.postMessage(startTime);
break;
case Mechanism.WKWebViewExecuteJs:
return startTime;
break;
}
}

0 comments on commit f678aac

Please sign in to comment.