Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8431010073 for ; Thu, 17 Apr 2014 16:13:25 +0000 (UTC) Received: (qmail 71859 invoked by uid 500); 17 Apr 2014 16:13:19 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 71819 invoked by uid 500); 17 Apr 2014 16:13:17 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 71756 invoked by uid 99); 17 Apr 2014 16:13:15 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Apr 2014 16:13:15 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9443D951B86; Thu, 17 Apr 2014 16:13:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Date: Thu, 17 Apr 2014 16:13:15 -0000 Message-Id: <800b8f5220664f659bd2b1e017dad112@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] spec commit: Add ArrayBuffer payload options to exec benchmark 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 Authored: Thu Apr 17 12:12:17 2014 -0400 Committer: Andrew Grieve 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 @@


+
+ These two require async_base64_android branch of cordova-js
+
+


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