diff options
author | Manolo Carrasco <manolo@apache.org> | 2011-04-10 06:51:23 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2011-04-10 06:51:23 +0000 |
commit | 7b7edb5b840175464f13f6082b9486e499c689e2 (patch) | |
tree | 3addfea904fd2a8c4ce695eb1af87cec9d607357 /samples | |
parent | 96a26ba48ef505e3fe096e3db97657bc91a59ed5 (diff) | |
download | gwtquery-7b7edb5b840175464f13f6082b9486e499c689e2.tar.gz gwtquery-7b7edb5b840175464f13f6082b9486e499c689e2.zip |
Refactoring JsCollection benchmarking
Diffstat (limited to 'samples')
-rw-r--r-- | samples/pom.xml | 3 | ||||
-rw-r--r-- | samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java | 100 |
2 files changed, 51 insertions, 52 deletions
diff --git a/samples/pom.xml b/samples/pom.xml index 8bab088e..b4a4a04a 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -44,6 +44,8 @@ <gwtVersion>${gwtversion}</gwtVersion> <compileReport>true</compileReport> <modules> + <module>gwtquery.samples.JsCollectionVsJavaCollection</module> +<!-- <module>gwtquery.samples.GwtQueryBench</module> <module>gwtquery.samples.GwtQuerySample</module> <module>gwtquery.samples.GwtQueryDemo</module> @@ -53,6 +55,7 @@ <module>gwtquery.samples.GwtQueryImageZoom</module> <module>gwtquery.samples.FadeEffectsSample</module> <module>gwtquery.samples.SlideEffectsSample</module> +--> </modules> </configuration> <executions> diff --git a/samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java b/samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java index 14c06375..b4edf9e4 100644 --- a/samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java +++ b/samples/src/main/java/gwtquery/samples/client/JsCollectionVsJavaCollection.java @@ -2,18 +2,20 @@ package gwtquery.samples.client; import static com.google.gwt.query.client.GQuery.$; +import java.util.HashMap; + +import com.google.gwt.core.client.Duration; 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.query.client.js.JsObjectArray; 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; @@ -42,106 +44,100 @@ public class JsCollectionVsJavaCollection implements EntryPoint{ for (int i = 0; i < MAX_ITEMS; i++){ new String(""+i); } + double ellapsedTime, totalTime; JsCache cache = JsCache.create(); - JsMap<String, Object> jsMap = cache.cast(); - log("Testing jsMap : put "+MAX_ITEMS+" items in the map :"); - - long ellapsedTime = System.currentTimeMillis(); + log("Testing cache : put "+MAX_ITEMS+" items in the cache :"); + totalTime = ellapsedTime = Duration.currentTimeMillis(); for (int i = 0; i < MAX_ITEMS; i++){ - jsMap.put(new String(""+i), new Object()); + cache.put(new String(""+i), new Object()); } - ellapsedTime = System.currentTimeMillis() - ellapsedTime; + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; log(" ellapsed Time : "+ellapsedTime); - log("Testing jsMap : do "+MAX_ITEMS+" get in the map :"); - long totalTime = 0; - + log("Testing cache : do "+MAX_ITEMS+" get in the cache :"); + ellapsedTime = Duration.currentTimeMillis(); 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); + cache.get(new String(""+random)); } - log(" ellapsed Time : "+totalTime); - - log("Testing jsMap : do "+MAX_ITEMS+" exist (JsCache.exists() ) in the cache :"); - totalTime = 0; + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; + log(" ellapsed Time : "+ellapsedTime); + log("Testing cache : do "+MAX_ITEMS+" exist (JsCache.exists() ) in the cache :"); + ellapsedTime = Duration.currentTimeMillis(); 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; + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; log(" ellapsed Time : "+ellapsedTime); - log("Testing jsMap : get all values (JsCache.elements() ) :"); + log("Testing cache : get all keys :"); + ellapsedTime = Duration.currentTimeMillis(); + for (String s: cache.keys()) { + } + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; + log(" ellapsed Time : "+ellapsedTime); - ellapsedTime = System.currentTimeMillis(); - cache.elements(); - ellapsedTime = System.currentTimeMillis() - ellapsedTime; + log("Testing cache : get all values (JsCache.elements() ) :"); + ellapsedTime = Duration.currentTimeMillis(); + for (Object o: cache.elements()) { + } + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; log(" ellapsed Time : "+ellapsedTime); + totalTime = Duration.currentTimeMillis() - totalTime; + log(" Total : "+ totalTime); log("-------------"); log(""); HashMap<String, Object> hashMap = new HashMap<String, Object>(); log("Testing hashMap : put "+MAX_ITEMS+" items in the map :"); - ellapsedTime = System.currentTimeMillis(); + totalTime = ellapsedTime = Duration.currentTimeMillis(); for (int i = 0; i < MAX_ITEMS; i++){ hashMap.put(new String(""+i), new Object()); } - ellapsedTime = System.currentTimeMillis() - ellapsedTime; + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; log(" ellapsed Time : "+ellapsedTime); log("Testing hashMap : do "+MAX_ITEMS+" get in the map :"); - totalTime = 0; - + ellapsedTime = Duration.currentTimeMillis(); 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); + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; + log(" ellapsed Time : "+ellapsedTime); log("Testing hashMap : do "+MAX_ITEMS+" containsKey() :"); - totalTime = 0; - + ellapsedTime = Duration.currentTimeMillis(); 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); + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; + log(" ellapsed Time : "+ellapsedTime); log("Testing hashMap : get all keys :"); - - ellapsedTime = System.currentTimeMillis(); - hashMap.keySet(); - ellapsedTime = System.currentTimeMillis() - ellapsedTime; + ellapsedTime = Duration.currentTimeMillis(); + for (String s: hashMap.keySet()) { + } + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; log(" ellapsed Time : "+ellapsedTime); log("Testing hashMap : get all values :"); - - ellapsedTime = System.currentTimeMillis(); - hashMap.values(); - ellapsedTime = System.currentTimeMillis() - ellapsedTime; + ellapsedTime = Duration.currentTimeMillis(); + for (Object o : hashMap.values()) { + } + ellapsedTime = Duration.currentTimeMillis() - ellapsedTime; log(" ellapsed Time : "+ellapsedTime); + totalTime = Duration.currentTimeMillis() - totalTime; + log(" Total : "+ totalTime); log("-------------"); - } |