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/08 17:32:11 UTC

ios commit: Add a benchmark into CordovaLibApp for measuring exec() speed.

Updated Branches:
  refs/heads/master 444a89013 -> 2cef31367


Add a benchmark into CordovaLibApp for measuring exec() speed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/2cef3136
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/2cef3136
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/2cef3136

Branch: refs/heads/master
Commit: 2cef313671476dda7aa43ebef5206ac3f22815b7
Parents: 444a890
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Aug 8 11:28:37 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Aug 8 11:31:34 2012 -0400

----------------------------------------------------------------------
 CordovaLib/CordovaLibApp/Cordova.plist            |   22 +-----
 CordovaLib/CordovaLibApp/EchoPlugin.h             |   23 ++++++
 CordovaLib/CordovaLibApp/EchoPlugin.m             |   32 ++++++++
 CordovaLib/CordovaLibApp/www/index.html           |   62 +++++++++++++++-
 CordovaLib/CordovaTests.xcodeproj/project.pbxproj |    6 ++
 5 files changed, 124 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/2cef3136/CordovaLib/CordovaLibApp/Cordova.plist
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLibApp/Cordova.plist b/CordovaLib/CordovaLibApp/Cordova.plist
index 69d86a3..4725c8a 100644
--- a/CordovaLib/CordovaLibApp/Cordova.plist
+++ b/CordovaLib/CordovaLibApp/Cordova.plist
@@ -1,25 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<!--
-#
-# 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.
-#
--->
 <plist version="1.0">
 <dict>
 	<key>UIWebViewBounce</key>
@@ -76,6 +56,8 @@
 		<string>CDVCapture</string>
 		<key>SplashScreen</key>
 		<string>CDVSplashScreen</string>
+		<key>EchoPlugin</key>
+		<string>EchoPlugin</string>
 		<key>Battery</key>
 		<string>CDVBattery</string>
 	</dict>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/2cef3136/CordovaLib/CordovaLibApp/EchoPlugin.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLibApp/EchoPlugin.h b/CordovaLib/CordovaLibApp/EchoPlugin.h
new file mode 100644
index 0000000..3c5055d
--- /dev/null
+++ b/CordovaLib/CordovaLibApp/EchoPlugin.h
@@ -0,0 +1,23 @@
+/*
+ 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.
+ */
+
+#import "CDVPlugin.h"
+
+@interface EchoPlugin : CDVPlugin
+@end

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/2cef3136/CordovaLib/CordovaLibApp/EchoPlugin.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLibApp/EchoPlugin.m b/CordovaLib/CordovaLibApp/EchoPlugin.m
new file mode 100644
index 0000000..c1790a8
--- /dev/null
+++ b/CordovaLib/CordovaLibApp/EchoPlugin.m
@@ -0,0 +1,32 @@
+/*
+ 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.
+ */
+
+
+#import "EchoPlugin.h"
+#import "CDV.h"
+
+@implementation EchoPlugin
+
+- (void)echo:(CDVInvokedUrlCommand*)command
+{
+    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[command.arguments objectAtIndex:0]];
+    [self success:pluginResult callbackId:command.callbackId];
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/2cef3136/CordovaLib/CordovaLibApp/www/index.html
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLibApp/www/index.html b/CordovaLib/CordovaLibApp/www/index.html
index f7ec13c..bb6955a 100644
--- a/CordovaLib/CordovaLibApp/www/index.html
+++ b/CordovaLib/CordovaLibApp/www/index.html
@@ -69,9 +69,67 @@
     // Used by unit tests to tell when the page is loaded.
     window.pageIsLoaded = true;
 		// do your thing!
-		navigator.notification.alert("Cordova is working")
+		navigator.notification.alert("Cordova is working")        
 	}
     
+    var appLogElem;
+    function appLog(message) {
+        if (!appLogElem) {
+            appLogElem = document.getElementById('app-logs');
+        }
+        appLogElem.innerText += message + '\n';
+    }
+    
+    function benchExec()
+    {
+        appLog('Started exec benchmark');
+        var exec = cordova.require('cordova/exec'),
+            BENCH_DURATION_MS = 2000,
+            BENCH_PAYLOAD = 'This is a small test message.',
+            startTime = +new Date,
+            callCount = 0;
+        
+        function win(result) {
+            callCount++;
+            if (result != BENCH_PAYLOAD) {
+                appLog('Wrong echo data!');
+            }
+            var elapsedMs = new Date - startTime;
+            if (elapsedMs < BENCH_DURATION_MS) {
+                setTimeout(echoMessage, 0);
+            } else {
+                var callsPerSecond = callCount * 1000 / elapsedMs;
+                appLog('Calls per second: ' + callsPerSecond);
+            }
+        }
+        function fail() {
+            appLog('Call failed!');
+        }
+        function echoMessage() {
+            exec(win, fail, "EchoPlugin", "echo", [BENCH_PAYLOAD]);
+        }
+        echoMessage();
+        setTimeout(function() {
+            if (!callCount) {
+                alert('Echo plugin did not respond');
+            }
+        }, 500);
+        
+        // Benchmark results on agrieve's iPad 3:
+        // webView:shouldStartLoadWithRequest:navigationType:
+        // ~350 Echos per second.
+        // NSURLProtocol with XHR to gap:///gapready, not handling response:
+        // ~160 Echos per second.
+        // NSURLProtocol with XHR to http:///gapready, not handling response:
+        // ~215 Echos per second.
+        // NSURLProtocol with XHR to file:///gapready, not handling response:
+        // ~215 Echos per second.
+        // NSURLProtocol with XHR to about:/gapready, not handling response:
+        // ~160 Echos per second.
+        // NSURLProtocol with XHR to http:///gapready, *with* handling response:
+        // ~160 Echos per second.
+    }
+    
     </script>
   </head>
   <body onload="onBodyLoad()">
@@ -80,5 +138,7 @@
 		<li>Check your console log for any white-list rejection errors.</li>
 		<li>Add your allowed <strong>hosts</strong> in Cordova.plist/ExternalHosts (wildcards OK, don't enter the URL scheme)</li>
 	</ol>
+    <button onclick="benchExec()">Benchmark exec</button>
+    <pre id="app-logs"></pre>
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/2cef3136/CordovaLib/CordovaTests.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaTests.xcodeproj/project.pbxproj b/CordovaLib/CordovaTests.xcodeproj/project.pbxproj
index 3d1fda3..03bc898 100644
--- a/CordovaLib/CordovaTests.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaTests.xcodeproj/project.pbxproj
@@ -43,6 +43,7 @@
 		68A32D7E141030EB006B237C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 686357AA141002F100DF4CF2 /* UIKit.framework */; };
 		68A32D7F141030F3006B237C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 686357AC141002F100DF4CF2 /* Foundation.framework */; };
 		EB37019415D18B9A00BEBC43 /* libCordova.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EB37018C15D18B2E00BEBC43 /* libCordova.a */; };
+		EB68E0BA15D2BCF400885F79 /* EchoPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = EB68E0B915D2BCF400885F79 /* EchoPlugin.m */; };
 		EBA3554615A731F100F4DE24 /* CDVFakeFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */; };
 		EBA3556F15ABD0C900F4DE24 /* CDVFileTransferTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */; };
 /* End PBXBuildFile section */
@@ -105,6 +106,8 @@
 		686357DC14100B1600DF4CF2 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
 		68A32D7414103017006B237C /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
 		EB37018115D18B2D00BEBC43 /* CordovaLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = CordovaLib.xcodeproj; sourceTree = "<group>"; };
+		EB68E0B815D2BCF400885F79 /* EchoPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EchoPlugin.h; sourceTree = "<group>"; };
+		EB68E0B915D2BCF400885F79 /* EchoPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EchoPlugin.m; sourceTree = "<group>"; };
 		EBA3550F15A5F18900F4DE24 /* CDVWebViewTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDVWebViewTest.h; sourceTree = "<group>"; };
 		EBA3554415A731F100F4DE24 /* CDVFakeFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVFakeFileManager.h; sourceTree = "<group>"; };
 		EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVFakeFileManager.m; sourceTree = "<group>"; };
@@ -197,6 +200,8 @@
 				30F8AE1C152129DA006625B3 /* www */,
 				303A4076152124BB00182201 /* AppDelegate.h */,
 				303A4077152124BB00182201 /* AppDelegate.m */,
+				EB68E0B815D2BCF400885F79 /* EchoPlugin.h */,
+				EB68E0B915D2BCF400885F79 /* EchoPlugin.m */,
 				303A4079152124BB00182201 /* ViewController.h */,
 				303A407A152124BB00182201 /* ViewController.m */,
 				303A406E152124BB00182201 /* Supporting Files */,
@@ -400,6 +405,7 @@
 				303A4074152124BB00182201 /* main.m in Sources */,
 				303A4078152124BB00182201 /* AppDelegate.m in Sources */,
 				303A407B152124BB00182201 /* ViewController.m in Sources */,
+				EB68E0BA15D2BCF400885F79 /* EchoPlugin.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};