You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2013/01/14 23:06:00 UTC

spec commit: [mobile-spec] CB-2216: Bench ArrayBuffers

Updated Branches:
  refs/heads/master fa02bfdb9 -> f9ae3788b


[mobile-spec] CB-2216: Bench ArrayBuffers


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/f9ae3788
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/f9ae3788
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/f9ae3788

Branch: refs/heads/master
Commit: f9ae3788b8470be2344f298f7732c1e44ad9b34c
Parents: fa02bfd
Author: Michal Mocny <mm...@gmail.com>
Authored: Mon Jan 14 17:04:54 2013 -0500
Committer: Michal Mocny <mm...@gmail.com>
Committed: Mon Jan 14 17:05:21 2013 -0500

----------------------------------------------------------------------
 execbenchmark/arraybuffer.html |  130 +++++++++++++++++++++++++++++++++++
 execbenchmark/index.html       |    1 +
 2 files changed, 131 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f9ae3788/execbenchmark/arraybuffer.html
----------------------------------------------------------------------
diff --git a/execbenchmark/arraybuffer.html b/execbenchmark/arraybuffer.html
new file mode 100644
index 0000000..d8fbe6a
--- /dev/null
+++ b/execbenchmark/arraybuffer.html
@@ -0,0 +1,130 @@
+<!DOCTYPE html>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+
+<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'),
+        deviceReady = false;
+
+    function appLog(message) {
+        if (window.console) {
+            console.log(message);
+        }
+        if (typeof message != 'string') {
+            message = JSON.stringify(message);
+        }
+        document.getElementById('app-logs').innerText += message + '\n';
+    }
+
+    function benchExec() {
+        var echo = cordova.require('cordova/plugin/echo'),
+            startTime = +new Date,
+            callCount = 0,
+            durationMs = parseInt(document.getElementById('test-duration').value, 10) * 1000,
+            payloadSize = (+document.getElementById('payload-size').value) * 100,
+            payload = new ArrayBuffer(payloadSize);
+
+        var payloadView = new Uint8Array(payload);
+        for (var i=0; i<payloadView.length; i++) {
+            payloadView[i] = i;
+        }
+
+        function compareArrayBuffers(arr1, arr2) {
+            arr1 = new Uint8Array(arr1);
+            arr2 = new Uint8Array(arr2);
+            if (arr1.length != arr2.length)
+                return false;
+            for (var i = 0; i < arr1.length; ++i) {
+                if (arr1[i] != arr2[i]) {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        function win(result) {
+            callCount++;
+            if (!compareArrayBuffers(result, payload)) {
+                appLog('Wrong echo data!');
+                return;
+            }
+            var elapsedMs = new Date - startTime;
+            if (elapsedMs >= durationMs) {
+                var callsPerSecond = callCount * 1000 / elapsedMs;
+                appLog('Calls per second: ' + callsPerSecond);
+                return;
+            }
+            echoMessage();
+        }
+        function fail() {
+            appLog('Call failed!');
+        }
+        function echoMessage() {
+            echo(win, fail, payload); // TODO: test setTimeout
+        }
+
+        appLog('Started exec benchmark with payload length: ' + payloadView.length);
+        echoMessage();
+        setTimeout(function() {
+            if (!callCount) {
+                alert('Echo plugin did not respond');
+            }
+        }, 500);
+    }
+
+    document.addEventListener("deviceready", function() {
+        deviceReady = true;
+        appLog("Device = " + device.platform + " " + device.version);
+    }, 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>ArrayBuffer 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>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>&nbsp</h2><a href="javascript:" class="backBtn" onclick="backHome();">Back</a><br>
+    <div>Results:</div>
+    <pre id="app-logs" style="white-space:pre-wrap;line-height:initial"></pre>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f9ae3788/execbenchmark/index.html
----------------------------------------------------------------------
diff --git a/execbenchmark/index.html b/execbenchmark/index.html
index 6360d4a..35c9c36 100644
--- a/execbenchmark/index.html
+++ b/execbenchmark/index.html
@@ -140,6 +140,7 @@
 
   </head>
   <body id="stage" class="theme">
+    <a href="arraybuffer.html" class="btn large">ArrayBuffer Benchmark</a>
     <h1>exec() Benchmark</h1>
     Before running on Android, set the following constants in NativeToJsMessagingBridge:
     <ul>