You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/08/17 17:07:29 UTC
spec commit: Add an exec() bridge benchmarking page.
Updated Branches:
refs/heads/master 2ae688747 -> b6f805858
Add an exec() bridge benchmarking page.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/commit/b6f80585
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/tree/b6f80585
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/diff/b6f80585
Branch: refs/heads/master
Commit: b6f805858af6b44a500a3ab80086d1b7e75248bc
Parents: 2ae6887
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Aug 16 17:14:51 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Aug 17 11:00:55 2012 -0400
----------------------------------------------------------------------
execbenchmark/index.html | 136 +++++++++++++++++++++++++++++++++++++++++
index.html | 1 +
2 files changed, 137 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/b6f80585/execbenchmark/index.html
----------------------------------------------------------------------
diff --git a/execbenchmark/index.html b/execbenchmark/index.html
new file mode 100755
index 0000000..c2679ba
--- /dev/null
+++ b/execbenchmark/index.html
@@ -0,0 +1,136 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
+ <title>Cordova Mobile Spec</title>
+ <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ <script type="text/javascript" charset="utf-8" src="../cordova.js"></script>
+
+<script>
+ var exec = cordova.require('cordova/exec'),
+ appLogElem = null,
+ deviceReady = false;
+
+ function appLog(message) {
+ if (!appLogElem) {
+ appLogElem = document.getElementById('app-logs');
+ }
+ appLogElem.innerText += message + '\n';
+ if (window.console) {
+ console.log(message);
+ }
+ }
+
+ function clearLogs() {
+ appLogElem.innerHTML = '';
+ }
+
+ function benchExec() {
+ var echo = cordova.require('cordova/plugin/echo'),
+ startTime = +new Date,
+ callCount = 0,
+ durationMs = parseInt(document.getElementById('test-duration').value, 10) * 1000,
+ asyncEcho = !!document.getElementById('async-echo').value,
+ useSetTimeout = !!document.getElementById('use-setTimeout').value,
+ jsToNativeMode = document.getElementById('js-native-modes').value,
+ nativeToJsMode = document.getElementById('native-js-modes').value,
+ payloadSize = +document.getElementById('payload-size').value,
+ payload = new Array(payloadSize * 10 + 1).join('012\n\n 6789');
+
+ function win(result) {
+ callCount++;
+ if (result != payload) {
+ appLog('Wrong echo data!');
+ }
+ var elapsedMs = new Date - startTime;
+ if (elapsedMs < durationMs) {
+ if (useSetTimeout) {
+ setTimeout(echoMessage, 0);
+ } else {
+ echoMessage();
+ }
+ } else {
+ var callsPerSecond = callCount * 1000 / elapsedMs;
+ appLog('Calls per second: ' + callsPerSecond);
+ }
+ }
+ function fail() {
+ appLog('Call failed!');
+ }
+ function echoMessage() {
+ echo(win, fail, payload, asyncEcho);
+ }
+
+ var logMsg = 'Started exec benchmark with setTimeout: ' + useSetTimeout + ' payload length: ' + payload.length;
+ if (jsToNativeMode) {
+ exec.setJsToNativeBridgeMode(+jsToNativeMode);
+ logMsg += ' jsToNativeMode: ' + jsToNativeMode;
+ }
+ if (nativeToJsMode) {
+ exec.setNativeToJsBridgeMode(+nativeToJsMode);
+ logMsg += ' nativeToJsMode: ' + nativeToJsMode;
+ }
+ appLog(logMsg);
+ echoMessage();
+ setTimeout(function() {
+ if (!callCount) {
+ alert('Echo plugin did not respond');
+ }
+ }, 500);
+ }
+
+ function configure() {
+ function configureModes(elemId, modes) {
+ var selectElem = document.getElementById(elemId);
+ for (var modeName in modes) {
+ var optionElem = document.createElement('option');
+ optionElem.value = modes[modeName];
+ optionElem.innerText = modeName;
+ selectElem.appendChild(optionElem);
+ }
+ selectElem.parentNode.style.display = 'block';
+ }
+ if (exec.jsToNativeModes) {
+ configureModes('js-native-modes', exec.jsToNativeModes);
+ }
+ if (exec.nativeToJsModes) {
+ configureModes('native-js-modes', exec.nativeToJsModes);
+ }
+ }
+
+
+ document.addEventListener("deviceready", function() {
+ deviceReady = true;
+ appLog("Device="+device.platform+" "+device.version);
+ configure();
+ }, false);
+
+ window.onload = function() {
+ window.setTimeout(function() {
+ if (!deviceReady) {
+ alert("Error: Cordova did not initialize. Demo will not run correctly.");
+ }
+ }, 1000);
+ };
+
+</script>
+
+ </head>
+ <body id="stage" class="theme">
+ <h1>exec() Benchmark</h1>
+ <fieldset>
+ <legend>Settings</legend>
+ <label>Test Duration: <select id="test-duration"><option>1 Second</option><option>5 Seconds</option></select><br></label>
+ <label style="display:none">JS->Native Bridge Mode: <select id="js-native-modes"></select><br></label>
+ <label style="display:none">Native->JS Bridge Mode: <select id="native-js-modes"></select><br></label>
+ <label><input type="checkbox" id="use-setTimeout"> Force async JS->Native</label><br>
+ <label><input type="checkbox" id="async-echo"> Force async Native->JS</label><br>
+ <label>Payload size (in 100s of bytes) <input id="payload-size" value="5" style="width:100px"></label><br>
+ <button onclick="benchExec()">Benchmark exec</button><br>
+ </fieldset>
+ <h2> </h2><a href="javascript:" class="backBtn" onclick="backHome();">Back</a><br>
+ <div>Results: <a href="javascript:clearLogs();">Clear</a></div>
+ <pre id="app-logs" style="white-space:pre-wrap;line-height:initial"></pre>
+ </body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/b6f80585/index.html
----------------------------------------------------------------------
diff --git a/index.html b/index.html
index 9c6f3cb..8534382 100755
--- a/index.html
+++ b/index.html
@@ -33,5 +33,6 @@
<a href="notification/index.html" class="btn large">Notification</a>
<a href="sql/index.html" class="btn large">Web SQL</a>
<a href="storage/index.html" class="btn large">Local Storage</a>
+ <a href="execbenchmark/index.html" class="btn large">Benchmark exec()</a>
</body>
</html>