|
|
@@ -6,15 +6,20 @@
|
|
|
*/
|
|
|
package net.ranides.assira.collection.map;
|
|
|
|
|
|
-import com.google.caliper.Runner;
|
|
|
+import com.google.caliper.Param;
|
|
|
import com.google.caliper.SimpleBenchmark;
|
|
|
+import com.google.caliper.runner.InvalidBenchmarkException;
|
|
|
+import com.google.caliper.util.InvalidCommandException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.SortedMap;
|
|
|
import java.util.TreeMap;
|
|
|
+import net.ranides.assira.BenchmarkRunner;
|
|
|
import net.ranides.assira.math.Randomizer;
|
|
|
+import net.ranides.assira.text.Strings;
|
|
|
|
|
|
/**
|
|
|
+ * @todo (assira # 3) caliper automatic conversion to CSV
|
|
|
* Comparison of performance #get methods
|
|
|
*
|
|
|
* RESULTS:
|
|
|
@@ -56,82 +61,124 @@ import net.ranides.assira.math.Randomizer;
|
|
|
* @author ranides
|
|
|
*/
|
|
|
public class SwitchMapBenchmark extends SimpleBenchmark {
|
|
|
-
|
|
|
- private IntMaps intTT;
|
|
|
- private IntMaps intSS;
|
|
|
- private IntMaps intSM;
|
|
|
- private IntMaps intSL;
|
|
|
- private IntMaps intMM;
|
|
|
- private IntMaps intLL;
|
|
|
- private IntMaps intED;
|
|
|
|
|
|
- private StrMaps strTT;
|
|
|
- private StrMaps strSS;
|
|
|
- private StrMaps strSM;
|
|
|
- private StrMaps strSL;
|
|
|
- private StrMaps strMM;
|
|
|
- private StrMaps strLL;
|
|
|
- private StrMaps strED;
|
|
|
-
|
|
|
+ public static final String PARAMS = Strings.raw(/*
|
|
|
+ FOR: Int_hash
|
|
|
+ FOR: Int_tree
|
|
|
+ FOR: Int_hash
|
|
|
+
|
|
|
+ HEADER: param, in, idomain
|
|
|
+
|
|
|
+ 0, 32, 1000
|
|
|
+ 1, 256, 1000
|
|
|
+ 2, 256, 100000
|
|
|
+ 3, 256, 1000000000
|
|
|
+ 4, 10000, 1000000000
|
|
|
+ 5, 100000, 1000000000
|
|
|
+ 6, 10000, 10000
|
|
|
+
|
|
|
+ FOR: Str_hash
|
|
|
+ FOR: Str_tree
|
|
|
+ FOR: Str_hash
|
|
|
+
|
|
|
+ HEADER: param, sn, sdomain
|
|
|
+ 0, 32, 100099
|
|
|
+ 1, 256, 100099
|
|
|
+ 2, 256, 10000099
|
|
|
+ 3, 256, 100000000099
|
|
|
+ 4, 10000, 100000000099
|
|
|
+ 5, 100000, 100000000099
|
|
|
+ 6, 10000, 1000099
|
|
|
+ */);
|
|
|
+
|
|
|
+ private static final IntParams[] IPARAMS = {
|
|
|
+ new IntParams( 32, 1_000 ),
|
|
|
+ new IntParams( 256, 1_000 ),
|
|
|
+ new IntParams( 256, 100_000 ),
|
|
|
+ new IntParams( 256, 1_000_000_000 ),
|
|
|
+ new IntParams( 10_000, 1_000_000_000 ),
|
|
|
+ new IntParams(100_000, 1_000_000_000 ),
|
|
|
+ new IntParams( 10_000, 10_000 )
|
|
|
+ };
|
|
|
+
|
|
|
+ private static final StrParams[] SPARAMS = {
|
|
|
+ new StrParams(32, 1_000 ),
|
|
|
+ new StrParams( 256, 1_000 ),
|
|
|
+ new StrParams( 256, 100_000 ),
|
|
|
+ new StrParams( 256, 1_000_000_000 ),
|
|
|
+ new StrParams( 10_000, 1_000_000_000 ),
|
|
|
+ new StrParams(100_000, 1_000_000_000 ),
|
|
|
+ new StrParams( 10_000, 10_000 )
|
|
|
+ };
|
|
|
+
|
|
|
+ @Param
|
|
|
+ private int param;
|
|
|
+
|
|
|
+ private IntParams iparams;
|
|
|
+ private StrParams sparams;
|
|
|
+
|
|
|
@Override
|
|
|
public void setUp() {
|
|
|
- intTT = new IntMaps( 32, 1_000 );
|
|
|
- intSS = new IntMaps( 256, 1_000 );
|
|
|
- intSM = new IntMaps( 256, 100_000 );
|
|
|
- intSL = new IntMaps( 256, 1_000_000_000 );
|
|
|
- intMM = new IntMaps( 10_000, 1_000_000_000 );
|
|
|
- intLL = new IntMaps(100_000, 1_000_000_000 );
|
|
|
- intED = new IntMaps( 10_000, 10_000 );
|
|
|
-
|
|
|
- strTT = new StrMaps( 32, 1_000 );
|
|
|
- strSS = new StrMaps( 256, 1_000 );
|
|
|
- strSM = new StrMaps( 256, 100_000 );
|
|
|
- strSL = new StrMaps( 256, 1_000_000_000 );
|
|
|
- strMM = new StrMaps( 10_000, 1_000_000_000 );
|
|
|
- strLL = new StrMaps(100_000, 1_000_000_000 );
|
|
|
- strED = new StrMaps( 10_000, 10_000 );
|
|
|
+ iparams = IPARAMS[param].init();
|
|
|
+ sparams = SPARAMS[param].init();
|
|
|
}
|
|
|
|
|
|
- private static final class IntMaps {
|
|
|
+ private static final class IntParams {
|
|
|
|
|
|
+ public final int n;
|
|
|
public final int domain;
|
|
|
- public final SortedMap<Integer,Character> tree;
|
|
|
- public final Map<Integer,Character> smap;
|
|
|
- public final Map<Integer,Character> hash;
|
|
|
|
|
|
- public IntMaps(int n, int domain) {
|
|
|
+ public transient SortedMap<Integer,Character> tree;
|
|
|
+ public transient Map<Integer,Character> smap;
|
|
|
+ public transient Map<Integer,Character> hash;
|
|
|
+
|
|
|
+ public IntParams(int n, int domain) {
|
|
|
+ this.n = n;
|
|
|
this.domain = domain;
|
|
|
- this.tree = new TreeMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public IntParams init() {
|
|
|
+ tree = new TreeMap<>();
|
|
|
for(int i=0; i<n; i++) {
|
|
|
int key = Randomizer.number(domain);
|
|
|
char val = Randomizer.character();
|
|
|
- this.tree.put(key, val);
|
|
|
+ tree.put(key, val);
|
|
|
}
|
|
|
- this.smap = new SwitchMap<>(tree);
|
|
|
- this.hash = new HashMap<>(tree);
|
|
|
+ smap = new SwitchMap<>(tree);
|
|
|
+ hash = new HashMap<>(tree);
|
|
|
+
|
|
|
+ return this;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static final class StrMaps {
|
|
|
+ private static final class StrParams {
|
|
|
|
|
|
+ public final int n;
|
|
|
public final int domain;
|
|
|
- public final SortedMap<String,Character> tree;
|
|
|
- public final Map<String,Character> smap;
|
|
|
- public final Map<String,Character> hash;
|
|
|
|
|
|
- public StrMaps(int n, int domain) {
|
|
|
+ public transient SortedMap<String,Character> tree;
|
|
|
+ public transient Map<String,Character> smap;
|
|
|
+ public transient Map<String,Character> hash;
|
|
|
+
|
|
|
+ public StrParams(int n, int domain) {
|
|
|
+ this.n = n;
|
|
|
this.domain = domain;
|
|
|
- this.tree = new TreeMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public StrParams init() {
|
|
|
+ tree = new TreeMap<>();
|
|
|
for(int i=0; i<n; i++) {
|
|
|
String key = Integer.toHexString(Randomizer.number(domain));
|
|
|
char val = Randomizer.character();
|
|
|
this.tree.put(key, val);
|
|
|
}
|
|
|
- this.smap = new SwitchMap<>(tree);
|
|
|
- this.hash = new HashMap<>(tree);
|
|
|
+ smap = new SwitchMap<>(tree);
|
|
|
+ hash = new HashMap<>(tree);
|
|
|
+
|
|
|
+ return this;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private int itimeIntMap(int reps, int domain, Map<Integer, Character> map) {
|
|
|
int c = 0;
|
|
|
for(int i=0; i<reps; i++) {
|
|
|
@@ -151,173 +198,33 @@ public class SwitchMapBenchmark extends SimpleBenchmark {
|
|
|
}
|
|
|
return c;
|
|
|
}
|
|
|
-//
|
|
|
-// public int timeIntSS_tree(int reps) {
|
|
|
-// return itimeIntMap(reps, intSS.domain, intSS.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntSM_tree(int reps) {
|
|
|
-// return itimeIntMap(reps, intSM.domain, intSM.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntSL_tree(int reps) {
|
|
|
-// return itimeIntMap(reps, intSL.domain, intSL.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntMM_tree(int reps) {
|
|
|
-// return itimeIntMap(reps, intMM.domain, intMM.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntLL_tree(int reps) {
|
|
|
-// return itimeIntMap(reps, intLL.domain, intLL.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntSS_hash(int reps) {
|
|
|
-// return itimeIntMap(reps, intSS.domain, intSS.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntSM_hash(int reps) {
|
|
|
-// return itimeIntMap(reps, intSM.domain, intSM.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntSL_hash(int reps) {
|
|
|
-// return itimeIntMap(reps, intSL.domain, intSL.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntMM_hash(int reps) {
|
|
|
-// return itimeIntMap(reps, intMM.domain, intMM.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntLL_hash(int reps) {
|
|
|
-// return itimeIntMap(reps, intLL.domain, intLL.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntSS_smap(int reps) {
|
|
|
-// return itimeIntMap(reps, intSS.domain, intSS.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntSM_smap(int reps) {
|
|
|
-// return itimeIntMap(reps, intSM.domain, intSM.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntSL_smap(int reps) {
|
|
|
-// return itimeIntMap(reps, intSL.domain, intSL.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntMM_smap(int reps) {
|
|
|
-// return itimeIntMap(reps, intMM.domain, intMM.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntED_smap(int reps) {
|
|
|
-// return itimeIntMap(reps, intED.domain, intED.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntED_tree(int reps) {
|
|
|
-// return itimeIntMap(reps, intED.domain, intED.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeIntED_hash(int reps) {
|
|
|
-// return itimeIntMap(reps, intED.domain, intED.hash);
|
|
|
-// }
|
|
|
|
|
|
- public int timeIntTT_smap(int reps) {
|
|
|
- return itimeIntMap(reps, intTT.domain, intTT.smap);
|
|
|
+ public int timeInt_smap(int reps) {
|
|
|
+ return itimeIntMap(reps, iparams.domain, iparams.smap);
|
|
|
}
|
|
|
|
|
|
- public int timeIntTT_tree(int reps) {
|
|
|
- return itimeIntMap(reps, intTT.domain, intTT.tree);
|
|
|
+ public int timeInt_tree(int reps) {
|
|
|
+ return itimeIntMap(reps, iparams.domain, iparams.tree);
|
|
|
}
|
|
|
|
|
|
- public int timeIntTT_hash(int reps) {
|
|
|
- return itimeIntMap(reps, intTT.domain, intTT.hash);
|
|
|
+ public int timeInt_hash(int reps) {
|
|
|
+ return itimeIntMap(reps, iparams.domain, iparams.hash);
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-// public int timeStrSS_tree(int reps) {
|
|
|
-// return itimeStrMap(reps, strSS.domain, strSS.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrSM_tree(int reps) {
|
|
|
-// return itimeStrMap(reps, strSM.domain, strSM.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrSL_tree(int reps) {
|
|
|
-// return itimeStrMap(reps, strSL.domain, strSL.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrMM_tree(int reps) {
|
|
|
-// return itimeStrMap(reps, strMM.domain, strMM.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrLL_tree(int reps) {
|
|
|
-// return itimeStrMap(reps, strLL.domain, strLL.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrSS_hash(int reps) {
|
|
|
-// return itimeStrMap(reps, strSS.domain, strSS.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrSM_hash(int reps) {
|
|
|
-// return itimeStrMap(reps, strSM.domain, strSM.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrSL_hash(int reps) {
|
|
|
-// return itimeStrMap(reps, strSL.domain, strSL.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrMM_hash(int reps) {
|
|
|
-// return itimeStrMap(reps, strMM.domain, strMM.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrLL_hash(int reps) {
|
|
|
-// return itimeStrMap(reps, strLL.domain, strLL.hash);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrSS_smap(int reps) {
|
|
|
-// return itimeStrMap(reps, strSS.domain, strSS.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrSM_smap(int reps) {
|
|
|
-// return itimeStrMap(reps, strSM.domain, strSM.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrSL_smap(int reps) {
|
|
|
-// return itimeStrMap(reps, strSL.domain, strSL.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrMM_smap(int reps) {
|
|
|
-// return itimeStrMap(reps, strMM.domain, strMM.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrLL_smap(int reps) {
|
|
|
-// return itimeStrMap(reps, strLL.domain, strLL.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrED_smap(int reps) {
|
|
|
-// return itimeStrMap(reps, strED.domain, strED.smap);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrED_tree(int reps) {
|
|
|
-// return itimeStrMap(reps, strED.domain, strED.tree);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public int timeStrED_hash(int reps) {
|
|
|
-// return itimeStrMap(reps, strED.domain, strED.hash);
|
|
|
-// }
|
|
|
-
|
|
|
- public int timeStrTT_smap(int reps) {
|
|
|
- return itimeStrMap(reps, strTT.domain, strTT.smap);
|
|
|
+ public int timeStr_smap(int reps) {
|
|
|
+ return itimeStrMap(reps, iparams.domain, sparams.smap);
|
|
|
}
|
|
|
|
|
|
- public int timeStrTT_tree(int reps) {
|
|
|
- return itimeStrMap(reps, strTT.domain, strTT.tree);
|
|
|
+ public int timeStr_tree(int reps) {
|
|
|
+ return itimeStrMap(reps, iparams.domain, sparams.tree);
|
|
|
}
|
|
|
|
|
|
- public int timeStrTT_hash(int reps) {
|
|
|
- return itimeStrMap(reps, strTT.domain, strTT.hash);
|
|
|
+ public int timeStr_hash(int reps) {
|
|
|
+ return itimeStrMap(reps, iparams.domain, sparams.hash);
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- Runner.main(SwitchMapBenchmark.class, args);
|
|
|
+ public static void main(String[] args) throws InvalidCommandException, InvalidBenchmarkException {
|
|
|
+ BenchmarkRunner.run32();
|
|
|
}
|
|
|
+
|
|
|
}
|