aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/src/main/java/gwtquery/samples/JsCollectionVsJavaCollection.gwt.xml7
-rw-r--r--samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java155
-rw-r--r--samples/src/main/java/gwtquery/samples/public/JsCollectionVsJavaCollection.html9
3 files changed, 171 insertions, 0 deletions
diff --git a/samples/src/main/java/gwtquery/samples/JsCollectionVsJavaCollection.gwt.xml b/samples/src/main/java/gwtquery/samples/JsCollectionVsJavaCollection.gwt.xml
new file mode 100644
index 00000000..3011cca5
--- /dev/null
+++ b/samples/src/main/java/gwtquery/samples/JsCollectionVsJavaCollection.gwt.xml
@@ -0,0 +1,7 @@
+<module rename-to='JsCollectionVsJavaCollection'>
+ <inherits name='com.google.gwt.query.Query' />
+ <entry-point
+ class="gwtquery.samples.client.JsCollectionVsJavaCollection">
+ </entry-point>
+</module>
+
diff --git a/samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java b/samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java
new file mode 100644
index 00000000..14c06375
--- /dev/null
+++ b/samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java
@@ -0,0 +1,155 @@
+package gwtquery.samples.client;
+
+import static com.google.gwt.query.client.GQuery.$;
+
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.query.client.js.JsCache;
+import com.google.gwt.query.client.js.JsMap;
+import com.google.gwt.user.client.Random;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.RootPanel;
+
+import java.util.HashMap;
+
+public class JsCollectionVsJavaCollection implements EntryPoint{
+
+ public static final int MAX_ITEMS = 100000;
+
+
+ public void onModuleLoad() {
+
+ Button b = new Button("run test");
+ b.addClickHandler(new ClickHandler() {
+
+ public void onClick(ClickEvent event) {
+ $(".gwt-label").remove();
+ testJsMapVsHashMap();
+ }
+ });
+
+ RootPanel.get().add(b);
+
+ }
+
+
+ public void testJsMapVsHashMap() {
+ log("Testing jsMap");
+
+ log("init phase");
+ for (int i = 0; i < MAX_ITEMS; i++){
+ new String(""+i);
+ }
+
+ JsCache cache = JsCache.create();
+ JsMap<String, Object> jsMap = cache.cast();
+
+ log("Testing jsMap : put "+MAX_ITEMS+" items in the map :");
+
+ long ellapsedTime = System.currentTimeMillis();
+ for (int i = 0; i < MAX_ITEMS; i++){
+ jsMap.put(new String(""+i), new Object());
+ }
+ ellapsedTime = System.currentTimeMillis() - ellapsedTime;
+ log(" ellapsed Time : "+ellapsedTime);
+
+ log("Testing jsMap : do "+MAX_ITEMS+" get in the map :");
+ long totalTime = 0;
+
+ for (int i = 0 ; i < MAX_ITEMS; i++){
+ int random = Random.nextInt(MAX_ITEMS);
+ ellapsedTime = System.currentTimeMillis();
+ jsMap.get(new String(""+random));
+ totalTime += (System.currentTimeMillis() - ellapsedTime);
+ }
+ log(" ellapsed Time : "+totalTime);
+
+ log("Testing jsMap : do "+MAX_ITEMS+" exist (JsCache.exists() ) in the cache :");
+ totalTime = 0;
+
+ for (int i = 0 ; i < MAX_ITEMS; i++){
+ int random = Random.nextInt(MAX_ITEMS);
+ ellapsedTime = System.currentTimeMillis();
+ cache.exists(new String(""+random));
+ totalTime += (System.currentTimeMillis() - ellapsedTime);
+ }
+ log(" ellapsed Time : "+totalTime);
+
+ log("Testing jsMap : get all keys :");
+
+ ellapsedTime = System.currentTimeMillis();
+ jsMap.keys();
+ ellapsedTime = System.currentTimeMillis() - ellapsedTime;
+ log(" ellapsed Time : "+ellapsedTime);
+
+ log("Testing jsMap : get all values (JsCache.elements() ) :");
+
+ ellapsedTime = System.currentTimeMillis();
+ cache.elements();
+ ellapsedTime = System.currentTimeMillis() - ellapsedTime;
+ log(" ellapsed Time : "+ellapsedTime);
+
+ log("-------------");
+ log("");
+
+ HashMap<String, Object> hashMap = new HashMap<String, Object>();
+
+ log("Testing hashMap : put "+MAX_ITEMS+" items in the map :");
+ ellapsedTime = System.currentTimeMillis();
+ for (int i = 0; i < MAX_ITEMS; i++){
+ hashMap.put(new String(""+i), new Object());
+ }
+ ellapsedTime = System.currentTimeMillis() - ellapsedTime;
+ log(" ellapsed Time : "+ellapsedTime);
+
+ log("Testing hashMap : do "+MAX_ITEMS+" get in the map :");
+ totalTime = 0;
+
+ for (int i = 0 ; i < MAX_ITEMS; i++){
+ int random = Random.nextInt(MAX_ITEMS);
+ ellapsedTime = System.currentTimeMillis();
+ hashMap.get(new String(""+random));
+ totalTime += (System.currentTimeMillis() - ellapsedTime);
+ }
+ log(" ellapsed Time : "+totalTime);
+
+ log("Testing hashMap : do "+MAX_ITEMS+" containsKey() :");
+ totalTime = 0;
+
+ for (int i = 0 ; i < MAX_ITEMS; i++){
+ int random = Random.nextInt(MAX_ITEMS);
+ ellapsedTime = System.currentTimeMillis();
+ hashMap.containsKey(new String(""+random));
+ totalTime += (System.currentTimeMillis() - ellapsedTime);
+ }
+ log(" ellapsed Time : "+totalTime);
+
+ log("Testing hashMap : get all keys :");
+
+ ellapsedTime = System.currentTimeMillis();
+ hashMap.keySet();
+ ellapsedTime = System.currentTimeMillis() - ellapsedTime;
+ log(" ellapsed Time : "+ellapsedTime);
+
+ log("Testing hashMap : get all values :");
+
+ ellapsedTime = System.currentTimeMillis();
+ hashMap.values();
+ ellapsedTime = System.currentTimeMillis() - ellapsedTime;
+ log(" ellapsed Time : "+ellapsedTime);
+
+ log("-------------");
+
+ }
+
+
+
+
+ public void log(String msg) {
+ RootPanel.get().add(new Label(msg));
+ }
+
+
+}
diff --git a/samples/src/main/java/gwtquery/samples/public/JsCollectionVsJavaCollection.html b/samples/src/main/java/gwtquery/samples/public/JsCollectionVsJavaCollection.html
new file mode 100644
index 00000000..32b9c535
--- /dev/null
+++ b/samples/src/main/java/gwtquery/samples/public/JsCollectionVsJavaCollection.html
@@ -0,0 +1,9 @@
+<html>
+<head>
+<title>GQuery Demo</title>
+<script language="javascript"
+ src="JsCollectionVsJavaCollection.nocache.js" ></script>
+</head>
+<body>
+</body>
+</html>