cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [1/2] spec commit: Add ArrayBuffer payload options to exec benchmark
Date Thu, 17 Apr 2014 16:13:15 GMT
Repository: cordova-mobile-spec
Updated Branches:
  refs/heads/master 4c1720479 -> 4dd6891f3


Add ArrayBuffer payload options to exec benchmark


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/4dd6891f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/4dd6891f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/4dd6891f

Branch: refs/heads/master
Commit: 4dd6891f30972bbad75fc7e9241d38d6165e99ff
Parents: 24f3854
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Apr 17 12:12:17 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Apr 17 12:13:08 2014 -0400

----------------------------------------------------------------------
 benchmarks/exec.html                      | 28 +++++++++++++++++++++++---
 cordova-plugin-echo/src/android/Echo.java |  9 +++++++++
 cordova-plugin-echo/src/ios/CDVEcho.m     |  8 ++++++++
 cordova-plugin-echo/www/echo.js           |  4 ++--
 4 files changed, 44 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4dd6891f/benchmarks/exec.html
----------------------------------------------------------------------
diff --git a/benchmarks/exec.html b/benchmarks/exec.html
index b9339e8..cd51ca4 100644
--- a/benchmarks/exec.html
+++ b/benchmarks/exec.html
@@ -56,6 +56,18 @@
         cordova.echo.stopBulkEcho();
     }
 
+    function createPayload(size, binary) {
+        if (!binary) {
+            return new Array(size * 10 + 1).join('012\n\n 6789');
+        }
+        size = size * 100;
+        var bufView = new Uint8Array(size);
+        for (var i = 0; i < size; ++i) {
+          bufView[i] = i % 20;
+        }
+        return bufView.buffer;
+    }
+
     function benchExec() {
         updateUi(!inProgress);
         if (!inProgress) {
@@ -74,8 +86,14 @@
             jsToNativeMode = document.getElementById('js-native-modes').value,
             nativeToJsMode = document.getElementById('native-js-modes').value,
             payloadSize = +document.getElementById('payload-size').value,
+            binaryPayload = document.getElementById('binary-payload').checked,
+            binaryAsyncEncode = document.getElementById('binary-async-encode').checked,
+            binaryAsyncDecode = document.getElementById('binary-async-decode').checked,
             soFarEl = document.getElementById('so-far'),
-            payload = new Array(payloadSize * 10 + 1).join('012\n\n 6789');
+            payload = createPayload(payloadSize, binaryPayload);
+
+        cordova.ASYNC_AB_ENCODE = binaryAsyncEncode;
+        cordova.ASYNC_AB_DECODE = binaryAsyncDecode;
 
         function reportProgress() {
             var callsPerSecond = String(callCount * 1000 / elapsedMs).slice(0, 6);
@@ -88,7 +106,7 @@
                 return;
             }
             callCount++;
-            if (result != payload) {
+            if (result.length !== payload.length || result.byteLength !== payload.byteLength)
{
                 appLog('Wrong echo data!');
                 updateUi(false);
             }
@@ -117,7 +135,7 @@
             echo(win, fail, payload, asyncEcho);
         }
 
-        var logMsg = 'Started exec benchmark with setTimeout: ' + useSetTimeout + ' asyncEcho:
' + asyncEcho + ' payload length: ' + payload.length;
+        var logMsg = 'Started exec benchmark with setImmediate: ' + useSetTimeout + ' asyncEcho:
' + asyncEcho + ' payload length: ' + payloadSize;
         if (jsToNativeMode) {
             exec.setJsToNativeBridgeMode(+jsToNativeMode);
             logMsg += ' jsToNativeMode: ' + jsToNativeMode;
@@ -202,6 +220,10 @@
         <label><input type="checkbox" id="use-setTimeout"> Force async JS-&gt;Native
(avoids evalAndFetch optimization on iOS)</label><br>
         <label><input type="checkbox" id="async-echo"> Force async Native-&gt;JS</label><br>
         <label><input type="checkbox" id="bulk-echo"> Bulk Echo Mode (test only
native-&gt;JS)</label><br>
+        <label><input type="checkbox" id="binary-payload"> Binary Payload</label><br>
+        These two require async_base64_android branch of cordova-js<br>
+        <label><input type="checkbox" id="binary-async-encode"> Use FileReader
to encode binary</label><br>
+        <label><input type="checkbox" id="binary-async-decode"> Use XHR to decode
binary</label><br>
         <label>Payload size (in 100s of bytes) <input id="payload-size" value="5"
style="width:100px"></label><br>
         <button id="go-btn" onclick="benchExec()">Start</button><br>
     </fieldset>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4dd6891f/cordova-plugin-echo/src/android/Echo.java
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/src/android/Echo.java b/cordova-plugin-echo/src/android/Echo.java
index 9837f9c..80e1ac7 100644
--- a/cordova-plugin-echo/src/android/Echo.java
+++ b/cordova-plugin-echo/src/android/Echo.java
@@ -62,6 +62,15 @@ public class Echo extends CordovaPlugin {
                 byte[] rawData= Base64.decode(data, Base64.DEFAULT);
             	callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, rawData));
                 return true;
+            } else if(action.equals("echoArrayBufferAsync")) {
+                cordova.getThreadPool().execute(new Runnable() {
+                    public void run() {
+                        String data = args.optString(0);
+                        byte[] rawData= Base64.decode(data, Base64.DEFAULT);
+                        callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK,
rawData));
+                    }
+                });
+                return true;
             } else if(action.equals("echoMultiPart")) {
             	callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, args.getJSONObject(0)));
                 return true;

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4dd6891f/cordova-plugin-echo/src/ios/CDVEcho.m
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/src/ios/CDVEcho.m b/cordova-plugin-echo/src/ios/CDVEcho.m
index e01ad14..212253a 100644
--- a/cordova-plugin-echo/src/ios/CDVEcho.m
+++ b/cordova-plugin-echo/src/ios/CDVEcho.m
@@ -53,6 +53,14 @@
     [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
 }
 
+- (void)echoArrayBufferAsync:(CDVInvokedUrlCommand*)command
+{
+    id message = [command.arguments objectAtIndex:0];
+    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsArrayBuffer:message];
+
+    [self performSelector:@selector(echoAsyncHelper:) withObject:[NSArray arrayWithObjects:pluginResult,
command.callbackId, nil] afterDelay:0];
+}
+
 - (void)echoMultiPart:(CDVInvokedUrlCommand*)command
 {
     CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsMultipart:command.arguments];

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4dd6891f/cordova-plugin-echo/www/echo.js
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/www/echo.js b/cordova-plugin-echo/www/echo.js
index 4e12953..1d75c8e 100644
--- a/cordova-plugin-echo/www/echo.js
+++ b/cordova-plugin-echo/www/echo.js
@@ -35,10 +35,10 @@ module.exports = function(successCallback, errorCallback, message, forceAsync)
{
     var args = messageIsMultipart ? message : [message];
 
     if (utils.typeName(message) == 'ArrayBuffer') {
+        action += 'ArrayBuffer';
         if (forceAsync) {
-            console.warn('Cannot echo ArrayBuffer with forced async, falling back to sync.');
+            action += 'Async';
         }
-        action += 'ArrayBuffer';
     } else if (messageIsMultipart) {
         if (forceAsync) {
             console.warn('Cannot echo MultiPart Array with forced async, falling back to
sync.');


Mime
View raw message