From 80501f64ae3415f91f12491bc1353efc23b99f5c Mon Sep 17 00:00:00 2001 From: vsonnier Date: Sun, 25 Jan 2015 16:06:28 +0100 Subject: [PATCH] #27: Ported Caliper benchs to JMH, removed Caliper for good --- .gitignore | 3 +- hppcrt-benchmarks/pom.xml | 313 +++++++++--------- .../src/main/assembly/binary.xml | 26 -- .../hppcrt/BenchmarkSuiteRunner.java | 188 +++++++++++ .../hppcrt/BigramCountingBase.java | 50 +-- .../hppcrt/{caliper => }/BroadWord.java | 2 +- .../hppcrt/{caliper => }/FastUtilMap.java | 2 +- .../hppcrt/{caliper => }/HppcMap.java | 2 +- .../hppcrt/{caliper => }/Implementations.java | 2 +- .../hppcrt/{caliper => }/JavaMap.java | 2 +- .../hppcrt/{caliper => }/MahoutMap.java | 2 +- .../{caliper => }/MapImplementation.java | 2 +- .../hppcrt/{caliper => }/TroveMap.java | 2 +- .../java/com/carrotsearch/hppcrt/Util.java | 2 +- .../caliper/BenchmarkBigramCounting.java | 67 ---- .../caliper/BenchmarkCollectionsSort.java | 146 -------- .../BenchmarkHashCollisionsAddAll.java | 122 ------- ...nchmarkHashCollisionsAddAllSuccessive.java | 126 ------- ...rkHashCollisionsDirectIterationAddAll.java | 133 -------- ...llisionsDirectIterationReversedAddAll.java | 133 -------- .../BenchmarkHashCollisionsForEachAddAll.java | 134 -------- .../hppcrt/caliper/BenchmarkPopCnt.java | 129 -------- .../hppcrt/caliper/BenchmarkSuite.java | 110 ------ .../hppcrt/jmh/BenchmarkBigramCounting.java | 86 +++++ .../hppcrt/jmh/BenchmarkCollectionsSort.java | 151 +++++++++ .../BenchmarkContainsWithRemoved.java | 46 +-- .../hppcrt/jmh/BenchmarkHashCollisions.java | 208 ++++++++++++ .../hppcrt/jmh/BenchmarkPopCnt.java | 142 ++++++++ .../hppcrt/{caliper => jmh}/BenchmarkPut.java | 42 ++- .../hppcrt/jub/HashMapBenchmark.java | 54 --- .../misc/BenchmarkHashContainersSuite.java | 129 +------- .../hppcrt/misc/HppcArraysBench.java | 21 +- .../hppcrt/misc/HppcHeapsSyntheticBench.java | 48 ++- .../hppcrt/misc/HppcListSyntheticBench.java | 26 +- .../hppcrt/misc/HppcMapSyntheticBench.java | 148 +++++---- .../hppcrt/misc/HppcSortSyntheticBench.java | 20 +- .../hppcrt/misc/SyntheticBenchmarkSuite.java | 77 +---- hppcrt-templateprocessor/pom.xml | 6 + pom.xml | 10 +- 39 files changed, 1175 insertions(+), 1737 deletions(-) delete mode 100644 hppcrt-benchmarks/src/main/assembly/binary.xml create mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BenchmarkSuiteRunner.java rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => }/BroadWord.java (99%) rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => }/FastUtilMap.java (97%) rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => }/HppcMap.java (96%) rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => }/Implementations.java (98%) rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => }/JavaMap.java (96%) rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => }/MahoutMap.java (97%) rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => }/MapImplementation.java (93%) rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => }/TroveMap.java (97%) delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkBigramCounting.java delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkCollectionsSort.java delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsAddAll.java delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsAddAllSuccessive.java delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsDirectIterationAddAll.java delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsDirectIterationReversedAddAll.java delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsForEachAddAll.java delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkPopCnt.java delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkSuite.java create mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkBigramCounting.java create mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkCollectionsSort.java rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => jmh}/BenchmarkContainsWithRemoved.java (65%) create mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkHashCollisions.java create mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkPopCnt.java rename hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/{caliper => jmh}/BenchmarkPut.java (60%) delete mode 100644 hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jub/HashMapBenchmark.java diff --git a/.gitignore b/.gitignore index 89386a5b2..838c49e24 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ target # Locally generated .builder.classpath -.benchmark.*.db \ No newline at end of file +.benchmark.*.db +*.mv.db diff --git a/hppcrt-benchmarks/pom.xml b/hppcrt-benchmarks/pom.xml index 7a08a04dd..f43da7f4b 100644 --- a/hppcrt-benchmarks/pom.xml +++ b/hppcrt-benchmarks/pom.xml @@ -1,171 +1,154 @@ - 4.0.0 + 4.0.0 - + + com.github.vsonnier + hppcrt-parent + 0.6.8-SNAPSHOT + ../pom.xml + + + com.github.vsonnier - hppcrt-parent + hppcrt-benchmarks 0.6.8-SNAPSHOT - ../pom.xml - - - - com.github.vsonnier - hppcrt-benchmarks - 0.6.8-SNAPSHOT - jar - - HPPC-RT Benchmarks - HPPC-RT benchmarks and comparison against other primitive collections. - - - true - ${basedir}/lib - - - - - - com.github.vsonnier - hppcrt - ${project.version} - - - - com.carrotsearch - junit-benchmarks - - - - com.h2database - h2 - 1.4.184 - - - - junit - junit - - - - commons-io - commons-io - 2.4 - - - - commons-lang - commons-lang - 2.6 - - - - net.sf.trove4j - trove4j - 3.0.3 - - - - it.unimi.dsi - fastutil - 6.6.0 - - - - com.google.caliper - caliper - 0.5-rc1 - - - com.google.code.gson - gson - - - - - - com.google.code.gson - gson - 2.2.4 - - - - org.apache.mahout - mahout-math - 0.9 - - - - org.apache.ant - ant - - - org.javolution - javolution-core-java - 6.0.0 - - - - - - - install - - - - org.apache.maven.plugins - maven-jar-plugin - - - - com.carrotsearch.hppcrt.caliper.BenchmarkSuite - false - true - - - mahout-math-0.9.jar - - - - - - - maven-assembly-plugin - - - src/main/assembly/binary.xml - - false - false - true - - jar-with-dependencies - - - - - assembly-binary - package - - single - - - - - - - - - - sonatype-nexus-public - SonaType public snapshots and releases repository - https://oss.sonatype.org/content/groups/public - - false - - - true - - - + jar + + HPPC-RT Benchmarks + HPPC-RT benchmarks and comparison against other primitive collections. + + + true + ${basedir}/lib + UTF-8 + 1.5 + 1.8 + benchmarks + + + + + + com.github.vsonnier + hppcrt + ${project.version} + + + + com.carrotsearch + junit-benchmarks + + + + com.h2database + h2 + 1.4.184 + + + + junit + junit + + + + commons-io + commons-io + 2.4 + + + + commons-lang + commons-lang + 2.6 + + + + net.sf.trove4j + trove4j + 3.0.3 + + + + it.unimi.dsi + fastutil + 6.6.1 + + + + org.openjdk.jmh + jmh-core-ct + ${jmh.version} + + + org.openjdk.jmh + jmh-core-it + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + provided + + + + org.apache.mahout + mahout-math + 0.9 + + + + org.apache.ant + ant + + + org.javolution + javolution-core-java + 6.0.0 + + + + + + install + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + package + + shade + + + ${uberjar.name} + + + org.openjdk.jmh.Main + + + + + + + + + + + + sonatype-nexus-public + SonaType public snapshots and releases repository + https://oss.sonatype.org/content/groups/public + + false + + + true + + + diff --git a/hppcrt-benchmarks/src/main/assembly/binary.xml b/hppcrt-benchmarks/src/main/assembly/binary.xml deleted file mode 100644 index dc640f36a..000000000 --- a/hppcrt-benchmarks/src/main/assembly/binary.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - binary - false - - - dir - - - - - / - true - runtime - ${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension} - - - / - true - system - ${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension} - - - diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BenchmarkSuiteRunner.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BenchmarkSuiteRunner.java new file mode 100644 index 000000000..4f63c4cdc --- /dev/null +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BenchmarkSuiteRunner.java @@ -0,0 +1,188 @@ +package com.carrotsearch.hppcrt; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import org.openjdk.jmh.runner.options.VerboseMode; + +public class BenchmarkSuiteRunner +{ + public static final int NB_MEASUREMENTS_DEFAULT = 10; + public static final int NB_WARMUPS_DEFAULT = 10; + + public static final String USAGE = "Usage : --- [--warmup=[nb of iterations, default 10]] [--measure=[nb of measurements, default 10]] "; + + public static class BenchmarkOptions + { + public int nbWarmups; + public int nbMeasurements; + + public BenchmarkOptions() { + + //nothing + } + + @Override + public String toString() { + + return "{nbMeasurements=" + this.nbMeasurements + ", nbWarmups=" + this.nbWarmups + "}"; + } + } + + public static class BenchmarkOptionException extends RuntimeException + { + private static final long serialVersionUID = 1L; + + public BenchmarkOptionException() { + super(); + + } + } + + public BenchmarkSuiteRunner() { + // nothing + } + + /** + * Analyze originalArgs as command line arguments to extract common parameters, + * in the format : --- [--warmup=[nb of warmups iterations, default 10] --measure=[nb of measurements, default 10]] , + * @param originalArgs + * @param commonOptions : extracted warmup and measurement values, with default values if not present + * @return the remaining command line args with the common options removed, for further processing by specific benchmarks. + * @throws BenchmarkOptionException if invalid command line + */ + public static final String[] parseCommonArguments(final String[] originalArgs, final BenchmarkOptions commonOptions) throws BenchmarkOptionException { + + //default values + commonOptions.nbMeasurements = BenchmarkSuiteRunner.NB_MEASUREMENTS_DEFAULT; + commonOptions.nbWarmups = BenchmarkSuiteRunner.NB_WARMUPS_DEFAULT; + + String fullArgString = ""; + + //Concat for split + for (final String strInd : originalArgs) { + + fullArgString += strInd + " "; + } + + final String[] parsedArgs = fullArgString.split("---"); + + //argument check + if (parsedArgs.length < 2) + { + System.out.println(BenchmarkSuiteRunner.USAGE); + throw new BenchmarkOptionException(); + } + + //Split again the 2nd part for warmup and measure checks: + final String[] remainingArgs = parsedArgs[1].trim().split("\\s"); + + final ArrayList specialArgs = new ArrayList(); + + for (final String commonArg : remainingArgs) { + + if (commonArg.contains("--warmup=")) { + + try { + commonOptions.nbWarmups = Integer.parseInt(commonArg.split("--warmup=")[1]); + } + finally { + //nothing, keep previous or default value, + } + } + else if (commonArg.contains("--measure=")) { + + try { + commonOptions.nbMeasurements = Integer.parseInt(commonArg.split("--measure=")[1]); + } + finally { + //nothing, keep previous or default value + } + } + else { + //copy the arg verbatim + specialArgs.add(commonArg.trim()); + } + } //end for common arg + + //return the remaining args, where warmup or measure args are stripped off the original list of args + return specialArgs.toArray(new String[specialArgs.size()]); + } + + /** + * Run the jmhClass JMH class with generic params, automatically parsing warmup and measure parameters + * from commandLine, then executing JMH with the provided JVM memory params. + * @param commandLine + * @param minHeapSizeMbytes + * @param maxHeapSizeMbytes + * @throws RunnerException + */ + public static void runJmhBasicBenchmarkWithCommandLine(final Class jmhClass, final String[] commandLine, + final int minHeapSizeMbytes, final int maxHeapSizeMbytes) throws RunnerException { + + final BenchmarkSuiteRunner.BenchmarkOptions commonOpts = new BenchmarkSuiteRunner.BenchmarkOptions(); + + //extract warmup and measurement args + BenchmarkSuiteRunner.parseCommonArguments(commandLine, commonOpts); + + BenchmarkSuiteRunner.runJmhBenchmark(jmhClass, + commonOpts.nbWarmups, commonOpts.nbMeasurements, + minHeapSizeMbytes, maxHeapSizeMbytes); + + } + + /** + * Run the jmhClass JMH class with generic params, automatically parsing warmup and measure parameters + * from commandLine, then executing JMH with warmup and measure parameters and the provided JVM memory params. + * @param commandLine + * @param minHeapSizeMbytes + * @param maxHeapSizeMbytes + * @throws RunnerException + */ + public static void runJmhBenchmark(final Class jmhClass, + final int nbWarmups, final int nbIterations, + final int minHeapSizeMbytes, final int maxHeapSizeMbytes) throws RunnerException { + + Util.printSystemInfo("Benchmarks for " + jmhClass.getSimpleName() + " starting..."); + + final Options opt = new OptionsBuilder() + .include(jmhClass.getSimpleName()) + .forks(1) + .mode(Mode.SingleShotTime) + .warmupIterations(nbWarmups) + .measurementIterations(nbIterations) + .verbosity(VerboseMode.NORMAL) + .jvmArgsAppend("-Xms" + minHeapSizeMbytes + "m") + .jvmArgsAppend("-Xmx" + maxHeapSizeMbytes + "m") + .build(); + + //run + new Runner(opt).run(); + } + + /** + * For each Class in runClasses, call its main(runArgs) method, so providing runArgs as + * if run with command line arguments. + */ + public static void runMain(final List> runClasses, final String[] runArgs) throws Exception + { + int i = 0; + + final int totalSize = runClasses.size(); + + for (final Class clz : runClasses) + { + Util.printHeader(clz.getSimpleName() + " (" + (++i) + "/" + totalSize + ")"); + + final Method method = clz.getDeclaredMethod("main", String[].class); + + method.invoke(null, new Object[] { runArgs }); + } + } +} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BigramCountingBase.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BigramCountingBase.java index 4fa84b9e0..6d76ba3bc 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BigramCountingBase.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BigramCountingBase.java @@ -17,10 +17,6 @@ public class BigramCountingBase /* Prepare some test data */ public static char[] DATA; - /* Prevent dead code removal. */ - public volatile int guard; - - @BeforeClass public static void prepareData() throws IOException { final byte[] dta = IOUtils.toByteArray( @@ -28,8 +24,7 @@ public static void prepareData() throws IOException BigramCountingBase.DATA = new String(dta, "UTF-8").toCharArray(); } - @Test - public void hppc() + public int hppc() { // [[[start:bigram-counting]]] // Some character data @@ -42,75 +37,82 @@ public void hppc() IntIntOpenHashMap.DEFAULT_CAPACITY, IntIntOpenHashMap.DEFAULT_LOAD_FACTOR); + int count = 0; + for (int i = 0; i < CHARS.length - 1; i++) { final int bigram = CHARS[i] << 16 | CHARS[i + 1]; - map.putOrAdd(bigram, 1, 1); + count += map.putOrAdd(bigram, 1, 1); } // [[[end:bigram-counting]]] - guard = map.size(); + return count; } - @Test - public void trove() + public int trove() { final char[] CHARS = BigramCountingBase.DATA; final TIntIntHashMap map = new TIntIntHashMap(); + int count = 0; + for (int i = 0; i < CHARS.length - 1; i++) { final int bigram = CHARS[i] << 16 | CHARS[i + 1]; - map.adjustOrPutValue(bigram, 1, 1); + count += map.adjustOrPutValue(bigram, 1, 1); } - guard = map.size(); + return count; } - @Test - public void mahoutCollections() + public int mahoutCollections() { final char[] CHARS = BigramCountingBase.DATA; final org.apache.mahout.math.map.OpenIntIntHashMap map = new org.apache.mahout.math.map.OpenIntIntHashMap(); + + int count = 0; + for (int i = 0; i < CHARS.length - 1; i++) { final int bigram = CHARS[i] << 16 | CHARS[i + 1]; - map.adjustOrPutValue(bigram, 1, 1); + count += map.adjustOrPutValue(bigram, 1, 1); } - guard = map.size(); + return count; } - @Test - public void fastutilOpenHashMap() + public int fastutilOpenHashMap() { final char[] CHARS = BigramCountingBase.DATA; final Int2IntOpenHashMap map = new Int2IntOpenHashMap(); map.defaultReturnValue(0); + int count = 0; + for (int i = 0; i < CHARS.length - 1; i++) { final int bigram = CHARS[i] << 16 | CHARS[i + 1]; - map.addTo(bigram, 1); + count += map.addTo(bigram, 1); } - guard = map.size(); + return count; } - @Test - public void fastutilLinkedOpenHashMap() + public int fastutilLinkedOpenHashMap() { final char[] CHARS = BigramCountingBase.DATA; final Int2IntLinkedOpenHashMap map = new Int2IntLinkedOpenHashMap(); map.defaultReturnValue(0); + int count = 0; + for (int i = 0; i < CHARS.length - 1; i++) { final int bigram = CHARS[i] << 16 | CHARS[i + 1]; - map.addTo(bigram, 1); + count += map.addTo(bigram, 1); } - guard = map.size(); + return count; } } \ No newline at end of file diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BroadWord.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BroadWord.java similarity index 99% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BroadWord.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BroadWord.java index 3bfc5c83e..2884bf738 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BroadWord.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/BroadWord.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt; /** * Methods and constants inspired by the article diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/FastUtilMap.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/FastUtilMap.java similarity index 97% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/FastUtilMap.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/FastUtilMap.java index d8e1092b7..6f2c81883 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/FastUtilMap.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/FastUtilMap.java @@ -1,4 +1,4 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/HppcMap.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/HppcMap.java similarity index 96% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/HppcMap.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/HppcMap.java index 524a9806e..aba85d1b3 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/HppcMap.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/HppcMap.java @@ -1,4 +1,4 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt; import com.carrotsearch.hppcrt.*; import com.carrotsearch.hppcrt.maps.*; diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/Implementations.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/Implementations.java similarity index 98% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/Implementations.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/Implementations.java index da06570cc..e01aa0426 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/Implementations.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/Implementations.java @@ -1,4 +1,4 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt; import com.carrotsearch.hppcrt.maps.*; import com.carrotsearch.hppcrt.strategies.IntStandardHash; diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/JavaMap.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/JavaMap.java similarity index 96% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/JavaMap.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/JavaMap.java index f95b3f715..bc9e689d2 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/JavaMap.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/JavaMap.java @@ -1,4 +1,4 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt; import java.util.HashMap; diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/MahoutMap.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/MahoutMap.java similarity index 97% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/MahoutMap.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/MahoutMap.java index 706d62431..8691f2f7b 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/MahoutMap.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/MahoutMap.java @@ -1,4 +1,4 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt; import org.apache.mahout.math.map.AbstractIntIntMap; import org.apache.mahout.math.map.OpenIntIntHashMap; diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/MapImplementation.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/MapImplementation.java similarity index 93% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/MapImplementation.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/MapImplementation.java index 67e568646..8b7044767 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/MapImplementation.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/MapImplementation.java @@ -1,4 +1,4 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt; /** * Something implementing a map interface (int-int). diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/TroveMap.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/TroveMap.java similarity index 97% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/TroveMap.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/TroveMap.java index bc5149f18..47a066951 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/TroveMap.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/TroveMap.java @@ -1,4 +1,4 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt; import com.carrotsearch.hppcrt.maps.*; diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/Util.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/Util.java index 374904a75..6b7f65683 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/Util.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/Util.java @@ -17,6 +17,7 @@ public class Util { + /** * shuffle array contents * @param array @@ -171,5 +172,4 @@ public static void printHeader(final String msg) System.out.println(StringUtils.repeat("=", 80)); System.out.flush(); } - } diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkBigramCounting.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkBigramCounting.java deleted file mode 100644 index b47654098..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkBigramCounting.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import com.carrotsearch.hppcrt.BigramCounting; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; - -/** - * Caliper version of {@link BigramCounting}. - */ -public class BenchmarkBigramCounting extends SimpleBenchmark -{ - private BigramCounting bc; - - @Param public Library library; - - public static enum Library - { - HPPC, - TROVE, - FASTUTIL_OPEN, - FASTUTIL_LINKED, - MAHOUT - } - - static - { - try - { - BigramCounting.prepareData(); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - @Override - protected void setUp() throws Exception - { - super.setUp(); - bc = new BigramCounting(); - } - - public int timeLibrary(int reps) - { - for (int i = 0; i < reps; i++) - { - switch (library) - { - case HPPC: bc.hppc(); break; - case TROVE: bc.trove(); break; - case FASTUTIL_LINKED: bc.fastutilLinkedOpenHashMap(); break; - case FASTUTIL_OPEN: bc.fastutilOpenHashMap(); break; - case MAHOUT: bc.mahoutCollections(); break; - } - } - - // No need to return computation result because BigramCounting saves a guard (?). - return 1; - } - - public static void main(String [] args) - { - Runner.main(BenchmarkBigramCounting.class, args); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkCollectionsSort.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkCollectionsSort.java deleted file mode 100644 index a314f9224..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkCollectionsSort.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; - -import com.carrotsearch.hppcrt.sorting.IndirectComparator; -import com.carrotsearch.hppcrt.sorting.IndirectSort; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; -import com.google.common.collect.Lists; - -/** - * Benchmark {@link Collections#sort(java.util.List)}, in particular for differences - * in the new JDK 1.7 (TimSort). The point of this benchmark is to get the order - * of elements (their indexes), not an array or collection of sorted elements (!). - */ -public class BenchmarkCollectionsSort extends SimpleBenchmark -{ - @Param("1000000") - public int size; - - private ArrayList data; - - //represent the initial index of data - private int[] indexes; - private int[] indexesClone; - private Integer[] indexesInteger; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - this.data = Lists.newArrayList(); - this.indexes = new int[size]; - this.indexesClone = new int[size]; - this.indexesInteger = new Integer[size]; - - for (int i = 0; i < size; i++) - { - data.add(Integer.toString(i)); - indexes[i] = i; - indexesInteger[i] = i; - } - - Collections.shuffle(data); - } - - /* - * - */ - public int timeIndirectMergeSort(int reps) - { - int count = 0; - for (int i = 0; i < reps; i++) - { - final Object [] input = data.toArray(); - int [] ordered = IndirectSort.mergesort(input, 0, input.length, new Comparator() - { - @SuppressWarnings({"unchecked", "rawtypes"}) - public int compare(Object o1, Object o2) - { - return ((Comparable) o1).compareTo(o2); - } - }); - - count += ordered[0]; - } - - return count; - } - - /* - * - */ - public int timeLegacySort(int reps) - { - System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); - return timeNewSort(reps); - } - - /* - * - */ - public int timeNewSort(int reps) - { - final Integer[] indexesClone = indexesInteger.clone(); - - int count = 0; - for (int i = 0; i < reps; i++) - { - Arrays.sort(indexesClone, new Comparator() - { - final ArrayList dta = data; - - @Override - public int compare(Integer o1, Integer o2) - { - return dta.get(o1.intValue()).compareTo( - dta.get(o2.intValue())); - } - }); - count += indexesClone[0]; - } - - return count; - } - - /* - * - */ - public int timeIndirectQuickSort(int reps) - { - int count = 0; - - //retry reps times - for (int i = 0; i < reps; i++) - { - //overwrite the same array, since it is modified in-place - System.arraycopy(indexes, 0, indexesClone, 0, indexes.length); - - IndirectSort.quicksort(0, indexesClone.length, new IndirectComparator() { - - final ArrayList dta = BenchmarkCollectionsSort.this.data; - - @Override - public int compare(int o1, int o2) - { - return dta.get(o1).compareTo(dta.get(o2)); - } - }, indexes); - - count += indexesClone[0]; - } //end for - - return count; - } - - public static void main(String [] args) - { - Runner.main(BenchmarkCollectionsSort.class, args); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsAddAll.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsAddAll.java deleted file mode 100644 index 5f9a337e9..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsAddAll.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import com.carrotsearch.hppcrt.DistributionGenerator; -import com.carrotsearch.hppcrt.XorShiftRandom; -import com.carrotsearch.hppcrt.predicates.IntPredicate; -import com.carrotsearch.hppcrt.procedures.IntProcedure; -import com.carrotsearch.hppcrt.sets.IntOpenHashSet; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; - -/** - * Benchmark putting All of a hashed container in another. - */ -public class BenchmarkHashCollisionsAddAll extends SimpleBenchmark -{ - /* Prepare some test data */ - public IntOpenHashSet testSet; - - public IntOpenHashSet currentUnderTestSet; - - public enum Distribution - { - RANDOM, LINEAR, LINEAR_DECREMENT, HIGHBITS; - } - - public enum Allocation - { - DEFAULT_SIZE, PREALLOCATED; - } - - @Param - public Allocation allocation; - - @Param - public Distribution distribution; - - @Param( - { - "5000000" - }) - public int size; - - /* - * - */ - @Override - protected void setUp() throws Exception - { - //Instead of this.size, fill up - //prepare testSet to be filled up to their specified load factor. - - this.testSet = new IntOpenHashSet(this.size); - - final DistributionGenerator gene = new DistributionGenerator(this.size, new XorShiftRandom(87955214455L)); - - int nextValue = -1; - - while (this.testSet.size() < this.testSet.capacity()) { - - if (this.distribution == Distribution.RANDOM) { - - nextValue = gene.RANDOM.getNext(); - } - else if (this.distribution == Distribution.LINEAR) { - - nextValue = gene.LINEAR.getNext(); - } - else if (this.distribution == Distribution.HIGHBITS) { - - nextValue = gene.HIGHBITS.getNext(); - } - else if (this.distribution == Distribution.LINEAR_DECREMENT) { - - nextValue = gene.LINEAR_DECREMENT.getNext(); - } - - this.testSet.add(nextValue); - } - - //Preallocate of not the tested hash containers - if (this.allocation == Allocation.DEFAULT_SIZE) { - - this.currentUnderTestSet = IntOpenHashSet.newInstance(); - - } - else if (this.allocation == Allocation.PREALLOCATED) { - - this.currentUnderTestSet = IntOpenHashSet.newInstanceWithCapacity(this.size, IntOpenHashSet.DEFAULT_LOAD_FACTOR); - - } - } - - @Override - protected void tearDown() throws Exception - { - this.testSet = null; - } - - /** - * Time the 'addAll' operation. - */ - public int timeSet_AddAll(final int reps) - { - int count = 0; - for (int i = 0; i < reps; i++) - { - this.currentUnderTestSet.clear(); - count += this.currentUnderTestSet.addAll(this.testSet); - } - return count; - } - - /** - * Running main - * @param args - */ - public static void main(final String[] args) - { - Runner.main(BenchmarkHashCollisionsAddAll.class, args); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsAddAllSuccessive.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsAddAllSuccessive.java deleted file mode 100644 index 120c79077..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsAddAllSuccessive.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import com.carrotsearch.hppcrt.DistributionGenerator; -import com.carrotsearch.hppcrt.XorShiftRandom; -import com.carrotsearch.hppcrt.predicates.IntPredicate; -import com.carrotsearch.hppcrt.procedures.IntProcedure; -import com.carrotsearch.hppcrt.sets.IntOpenHashSet; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; - -/** - * Benchmark putting All of a hashed container in another. - */ -public class BenchmarkHashCollisionsAddAllSuccessive extends SimpleBenchmark -{ - /* Prepare some test data */ - public IntOpenHashSet testSet; - - public IntOpenHashSet currentUnderTestSet; - - public IntOpenHashSet currentUnderTestSet2; - - public enum Distribution - { - RANDOM, LINEAR, LINEAR_DECREMENT, HIGHBITS; - } - - public enum Allocation - { - DEFAULT_SIZE, PREALLOCATED; - } - - @Param - public Allocation allocation; - - @Param - public Distribution distribution; - - @Param( - { - "5000000" - }) - public int size; - - /* - * - */ - @Override - protected void setUp() throws Exception - { - //Instead of this.size, fill up - //prepare testSet to be filled up to their specified load factor. - - this.testSet = new IntOpenHashSet(this.size); - - final DistributionGenerator gene = new DistributionGenerator(this.size, new XorShiftRandom(87955214455L)); - - int nextValue = -1; - - while (this.testSet.size() < this.testSet.capacity()) { - - if (this.distribution == Distribution.RANDOM) { - - nextValue = gene.RANDOM.getNext(); - } - else if (this.distribution == Distribution.LINEAR) { - - nextValue = gene.LINEAR.getNext(); - } - else if (this.distribution == Distribution.HIGHBITS) { - - nextValue = gene.HIGHBITS.getNext(); - } - else if (this.distribution == Distribution.LINEAR_DECREMENT) { - - nextValue = gene.LINEAR_DECREMENT.getNext(); - } - - this.testSet.add(nextValue); - } - - //Preallocate of not the tested hash containers - if (this.allocation == Allocation.DEFAULT_SIZE) { - - this.currentUnderTestSet = IntOpenHashSet.newInstance(); - this.currentUnderTestSet2 = IntOpenHashSet.newInstance(); - } - else if (this.allocation == Allocation.PREALLOCATED) { - - this.currentUnderTestSet = IntOpenHashSet.newInstanceWithCapacity(this.size, IntOpenHashSet.DEFAULT_LOAD_FACTOR); - this.currentUnderTestSet2 = IntOpenHashSet.newInstanceWithCapacity(this.size, IntOpenHashSet.DEFAULT_LOAD_FACTOR); - } - } - - @Override - protected void tearDown() throws Exception - { - this.testSet = null; - } - - /** - * Time the 'addAll' operation in successive ways - */ - public int timeSet_AddAll_Successive(final int reps) - { - int count = 0; - for (int i = 0; i < reps; i++) - { - this.currentUnderTestSet.clear(); - this.currentUnderTestSet2.clear(); - count += this.currentUnderTestSet.addAll(this.testSet); - count += this.currentUnderTestSet2.addAll(this.currentUnderTestSet); - } - return count; - } - - /** - * Running main - * @param args - */ - public static void main(final String[] args) - { - Runner.main(BenchmarkHashCollisionsAddAllSuccessive.class, args); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsDirectIterationAddAll.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsDirectIterationAddAll.java deleted file mode 100644 index ae8ce1e1f..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsDirectIterationAddAll.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import com.carrotsearch.hppcrt.DistributionGenerator; -import com.carrotsearch.hppcrt.XorShiftRandom; -import com.carrotsearch.hppcrt.predicates.IntPredicate; -import com.carrotsearch.hppcrt.procedures.IntProcedure; -import com.carrotsearch.hppcrt.sets.IntOpenHashSet; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; - -/** - * Benchmark putting All of a hashed container in another. - */ -public class BenchmarkHashCollisionsDirectIterationAddAll extends SimpleBenchmark -{ - /* Prepare some test data */ - public IntOpenHashSet testSet; - - public IntOpenHashSet currentUnderTestSet; - - public enum Distribution - { - RANDOM, LINEAR, LINEAR_DECREMENT, HIGHBITS; - } - - public enum Allocation - { - DEFAULT_SIZE, PREALLOCATED; - } - - @Param - public Allocation allocation; - - @Param - public Distribution distribution; - - @Param( - { - "5000000" - }) - public int size; - - /* - * - */ - @Override - protected void setUp() throws Exception - { - //Instead of this.size, fill up - //prepare testSet to be filled up to their specified load factor. - - this.testSet = new IntOpenHashSet(this.size); - - final DistributionGenerator gene = new DistributionGenerator(this.size, new XorShiftRandom(87955214455L)); - - int nextValue = -1; - - while (this.testSet.size() < this.testSet.capacity()) { - - if (this.distribution == Distribution.RANDOM) { - - nextValue = gene.RANDOM.getNext(); - } - else if (this.distribution == Distribution.LINEAR) { - - nextValue = gene.LINEAR.getNext(); - } - else if (this.distribution == Distribution.HIGHBITS) { - - nextValue = gene.HIGHBITS.getNext(); - } - else if (this.distribution == Distribution.LINEAR_DECREMENT) { - - nextValue = gene.LINEAR_DECREMENT.getNext(); - } - - this.testSet.add(nextValue); - } - - //Preallocate of not the tested hash containers - if (this.allocation == Allocation.DEFAULT_SIZE) { - - this.currentUnderTestSet = IntOpenHashSet.newInstance(); - - } - else if (this.allocation == Allocation.PREALLOCATED) { - - this.currentUnderTestSet = IntOpenHashSet.newInstanceWithCapacity(this.size, IntOpenHashSet.DEFAULT_LOAD_FACTOR); - - } - } - - @Override - protected void tearDown() throws Exception - { - this.testSet = null; - } - - /** - * Time the 'add all' by direct iteration on buffer operation. - */ - public int timeSet_Direct_iteration_add_all(final int reps) - { - int count = 0; - for (int i = 0; i < reps; i++) - { - this.currentUnderTestSet.clear(); - - final int[] testSetKeys = this.testSet.keys; - - for (int j = 0; j < testSetKeys.length; j++) { - - if (testSetKeys[j] != 0) { - - this.currentUnderTestSet.add(testSetKeys[j]); - } - } - - count += this.currentUnderTestSet.size(); - } - return count; - } - - /** - * Running main - * @param args - */ - public static void main(final String[] args) - { - Runner.main(BenchmarkHashCollisionsDirectIterationAddAll.class, args); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsDirectIterationReversedAddAll.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsDirectIterationReversedAddAll.java deleted file mode 100644 index 2d9bcb960..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsDirectIterationReversedAddAll.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import com.carrotsearch.hppcrt.DistributionGenerator; -import com.carrotsearch.hppcrt.XorShiftRandom; -import com.carrotsearch.hppcrt.predicates.IntPredicate; -import com.carrotsearch.hppcrt.procedures.IntProcedure; -import com.carrotsearch.hppcrt.sets.IntOpenHashSet; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; - -/** - * Benchmark putting All of a hashed container in another. - */ -public class BenchmarkHashCollisionsDirectIterationReversedAddAll extends SimpleBenchmark -{ - /* Prepare some test data */ - public IntOpenHashSet testSet; - - public IntOpenHashSet currentUnderTestSet; - - public enum Distribution - { - RANDOM, LINEAR, LINEAR_DECREMENT, HIGHBITS; - } - - public enum Allocation - { - DEFAULT_SIZE, PREALLOCATED; - } - - @Param - public Allocation allocation; - - @Param - public Distribution distribution; - - @Param( - { - "5000000" - }) - public int size; - - /* - * - */ - @Override - protected void setUp() throws Exception - { - //Instead of this.size, fill up - //prepare testSet to be filled up to their specified load factor. - - this.testSet = new IntOpenHashSet(this.size); - - final DistributionGenerator gene = new DistributionGenerator(this.size, new XorShiftRandom(87955214455L)); - - int nextValue = -1; - - while (this.testSet.size() < this.testSet.capacity()) { - - if (this.distribution == Distribution.RANDOM) { - - nextValue = gene.RANDOM.getNext(); - } - else if (this.distribution == Distribution.LINEAR) { - - nextValue = gene.LINEAR.getNext(); - } - else if (this.distribution == Distribution.HIGHBITS) { - - nextValue = gene.HIGHBITS.getNext(); - } - else if (this.distribution == Distribution.LINEAR_DECREMENT) { - - nextValue = gene.LINEAR_DECREMENT.getNext(); - } - - this.testSet.add(nextValue); - } - - //Preallocate of not the tested hash containers - if (this.allocation == Allocation.DEFAULT_SIZE) { - - this.currentUnderTestSet = IntOpenHashSet.newInstance(); - - } - else if (this.allocation == Allocation.PREALLOCATED) { - - this.currentUnderTestSet = IntOpenHashSet.newInstanceWithCapacity(this.size, IntOpenHashSet.DEFAULT_LOAD_FACTOR); - - } - } - - @Override - protected void tearDown() throws Exception - { - this.testSet = null; - } - - /** - * Time the 'add all' by direct iteration on buffer operation. - */ - public int timeSet_Direct_iteration_reversed_add_all(final int reps) - { - int count = 0; - for (int i = 0; i < reps; i++) - { - this.currentUnderTestSet.clear(); - - final int[] testSetKeys = this.testSet.keys; - - for (int j = testSetKeys.length - 1; j >= 0; j--) { - - if (testSetKeys[j] != 0) { - - this.currentUnderTestSet.add(testSetKeys[j]); - } - } - - count += this.currentUnderTestSet.size(); - } - return count; - } - - /** - * Running main - * @param args - */ - public static void main(final String[] args) - { - Runner.main(BenchmarkHashCollisionsDirectIterationReversedAddAll.class, args); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsForEachAddAll.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsForEachAddAll.java deleted file mode 100644 index b69336151..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkHashCollisionsForEachAddAll.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import com.carrotsearch.hppcrt.DistributionGenerator; -import com.carrotsearch.hppcrt.XorShiftRandom; -import com.carrotsearch.hppcrt.predicates.IntPredicate; -import com.carrotsearch.hppcrt.procedures.IntProcedure; -import com.carrotsearch.hppcrt.sets.IntOpenHashSet; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; - -/** - * Benchmark putting All of a hashed container in another. - */ -public class BenchmarkHashCollisionsForEachAddAll extends SimpleBenchmark -{ - /* Prepare some test data */ - public IntOpenHashSet testSet; - - public IntOpenHashSet currentUnderTestSet; - - public enum Distribution - { - RANDOM, LINEAR, LINEAR_DECREMENT, HIGHBITS; - } - - public enum Allocation - { - DEFAULT_SIZE, PREALLOCATED; - } - - @Param - public Allocation allocation; - - @Param - public Distribution distribution; - - @Param( - { - "5000000" - }) - public int size; - - /* - * - */ - @Override - protected void setUp() throws Exception - { - //Instead of this.size, fill up - //prepare testSet to be filled up to their specified load factor. - - this.testSet = new IntOpenHashSet(this.size); - - final DistributionGenerator gene = new DistributionGenerator(this.size, new XorShiftRandom(87955214455L)); - - int nextValue = -1; - - while (this.testSet.size() < this.testSet.capacity()) { - - if (this.distribution == Distribution.RANDOM) { - - nextValue = gene.RANDOM.getNext(); - } - else if (this.distribution == Distribution.LINEAR) { - - nextValue = gene.LINEAR.getNext(); - } - else if (this.distribution == Distribution.HIGHBITS) { - - nextValue = gene.HIGHBITS.getNext(); - } - else if (this.distribution == Distribution.LINEAR_DECREMENT) { - - nextValue = gene.LINEAR_DECREMENT.getNext(); - } - - this.testSet.add(nextValue); - } - - //Preallocate of not the tested hash containers - if (this.allocation == Allocation.DEFAULT_SIZE) { - - this.currentUnderTestSet = IntOpenHashSet.newInstance(); - - } - else if (this.allocation == Allocation.PREALLOCATED) { - - this.currentUnderTestSet = IntOpenHashSet.newInstanceWithCapacity(this.size, IntOpenHashSet.DEFAULT_LOAD_FACTOR); - - } - } - - @Override - protected void tearDown() throws Exception - { - this.testSet = null; - } - - /** - * Time the 'addAll' operation using a forEach() - */ - public int timeSet_ForEach_add_all(final int reps) - { - final IntProcedure addAllProcedure = new IntProcedure() { - - @Override - public final void apply(final int value) { - - BenchmarkHashCollisionsForEachAddAll.this.currentUnderTestSet.add(value); - } - }; - - int count = 0; - for (int i = 0; i < reps; i++) - { - this.currentUnderTestSet.clear(); - - this.testSet.forEach(addAllProcedure); - - count += this.currentUnderTestSet.size(); - } - return count; - } - - /** - * Running main - * @param args - */ - public static void main(final String[] args) - { - Runner.main(BenchmarkHashCollisionsForEachAddAll.class, args); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkPopCnt.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkPopCnt.java deleted file mode 100644 index 1d8205e58..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkPopCnt.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import java.util.Arrays; -import java.util.Random; - -import com.carrotsearch.hppcrt.BigramCounting; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; - -/** - * Caliper version of {@link BigramCounting}. - */ -public class BenchmarkPopCnt extends SimpleBenchmark -{ - long [] seq; - - @Param public Distribution distribution; - - public static enum Distribution - { - ZEROS, - FULL, - RANDOM, - ONEBIT - } - - @Override - protected void setUp() throws Exception - { - seq = new long [1000000]; - - Random rnd = new Random(0xdeadbeef); - switch (distribution) { - case ZEROS: - break; - case FULL: - Arrays.fill(seq, -1); - break; - case RANDOM: - for (int i = 0; i < seq.length; i++) { - seq[i] = rnd.nextLong(); - } - break; - case ONEBIT: - for (int i = 0; i < seq.length; i++) { - seq[i] = 1L << rnd.nextInt(64); - } - break; - } - } - - public int timeLongBitCount(int reps) { - int v = 0; - for (int i = 0; i < reps; i++) { - for (int j = 0; j < seq.length; j++) { - v += Long.bitCount(seq[j]); - } - } - return v; - } - - public int timeHdPopCnd(int reps) { - int v = 0; - for (int i = 0; i < reps; i++) { - for (int j = 0; j < seq.length; j++) { - v += hdBitCount(seq[j]); - } - } - return v; - } - - public int timeRank9(int reps) { - int v = 0; - for (int i = 0; i < reps; i++) { - for (int j = 0; j < seq.length; j++) { - v += rank9(seq[j]); - } - } - return v; - } - - public int _timeNaivePopCnt(int reps) { - int v = 0; - for (int i = 0; i < reps; i++) { - for (int j = 0; j < seq.length; j++) { - v += naivePopCnt(seq[j]); - } - } - return v; - } - - public static int naivePopCnt(long x) { - int cnt = 0; - while (x != 0) { - if (((x >>>= 1) & 1) != 0L) { - cnt++; - } - } - return cnt; - } - - public static int hdBitCount(long i) { - // HD, Figure 5-14 - i = i - ((i >>> 1) & 0x5555555555555555L); - i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L); - i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL; - i = i + (i >>> 8); - i = i + (i >>> 16); - i = i + (i >>> 32); - return (int)i & 0x7f; - } - - public static int rank9(long x) { - // Step 0 leaves in each pair of bits the number of ones originally contained in that pair: - x = x - ((x & 0xAAAAAAAAAAAAAAAAL) >>> 1); - // Step 1, idem for each nibble: - x = (x & 0x3333333333333333L) + ((x >>> 2) & 0x3333333333333333L); - // Step 2, idem for each byte: - x = (x + (x >>> 4)) & 0x0F0F0F0F0F0F0F0FL; - // Multiply to sum them all into the high byte, and return the high byte: - return (int) ((x * BroadWord.L8_L) >>> 56); - } - - public static void main(String [] args) - { - Runner.main(BenchmarkPopCnt.class, args); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkSuite.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkSuite.java deleted file mode 100644 index 1d2851de8..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkSuite.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.carrotsearch.hppcrt.caliper; - -import java.util.ArrayDeque; -import java.util.Arrays; -import java.util.Deque; -import java.util.List; - -import com.carrotsearch.hppcrt.Util; -import com.carrotsearch.hppcrt.misc.BenchmarkHashContainersSuite; -import com.google.caliper.Benchmark; -import com.google.caliper.Runner; -import com.google.common.collect.Lists; -import com.google.common.collect.ObjectArrays; - -/** - * Runs the entire suite of benchmarks. - */ -public class BenchmarkSuite -{ - @SuppressWarnings("unchecked") - private final static Class[] ALL_BENCHMARKS = new Class[] - { - BenchmarkHashCollisionsAddAll.class, - BenchmarkHashCollisionsAddAllSuccessive.class, - BenchmarkHashCollisionsDirectIterationAddAll.class, - BenchmarkHashCollisionsDirectIterationReversedAddAll.class, - BenchmarkHashCollisionsForEachAddAll.class, - BenchmarkPut.class, - BenchmarkContainsWithRemoved.class, - BenchmarkPopCnt.class, - BenchmarkBigramCounting.class, - BenchmarkCollectionsSort.class, - - }; - - public static void main(final String[] args) throws Exception - { - if (args.length == 0) - { - System.out.println("Args: [all | class-name, class-name, ...] [-- ]"); - System.out.println("Known benchmark classes: "); - for (final Class clz : BenchmarkSuite.ALL_BENCHMARKS) - { - System.out.println("\t" + clz.getName()); - } - return; - } - - final Deque argsList = new ArrayDeque(Arrays.asList(args)); - - final List> classes = Lists.newArrayList(); - - while (!argsList.isEmpty()) - { - if ("--".equals(argsList.peekFirst())) - { - argsList.removeFirst(); - break; - } - else if ("all".equals(argsList.peekFirst())) - { - argsList.removeFirst(); - classes.addAll(Arrays.asList(BenchmarkSuite.ALL_BENCHMARKS)); - } - else - { - final ClassLoader clLoader = Thread.currentThread() - .getContextClassLoader(); - - final String clz = argsList.removeFirst(); - try - { - @SuppressWarnings("unchecked") - final Class clzInstance = - (Class) Class.forName(clz, true, clLoader); - - if (!Benchmark.class.isAssignableFrom(clzInstance)) - { - System.out.println("Not a benchmark class: " + clz); - System.exit(-1); - } - - classes.add(clzInstance); - } - catch (final ClassNotFoundException e) - { - System.out.println("Class not found: " + clz); - System.exit(-1); - } - } - } - - Util.printSystemInfo("Benchmarks suite starting."); - BenchmarkSuite.runBenchmarks(classes, argsList.toArray(new String[argsList.size()])); - } - - /** - * - */ - private static void runBenchmarks(final List> classes, - final String[] args) throws Exception - { - int i = 0; - for (final Class clz : classes) - { - Util.printHeader(clz.getSimpleName() + " (" + (++i) + "/" + classes.size() + ")"); - new Runner().run(ObjectArrays.concat(args, clz.getName())); - } - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkBigramCounting.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkBigramCounting.java new file mode 100644 index 000000000..167c98b95 --- /dev/null +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkBigramCounting.java @@ -0,0 +1,86 @@ +package com.carrotsearch.hppcrt.jmh; + +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.RunnerException; + +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; +import com.carrotsearch.hppcrt.BigramCounting; +import com.carrotsearch.hppcrt.BigramCountingBase; + +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +public class BenchmarkBigramCounting +{ + private BigramCounting bc; + + @Param + public Library library; + + public static enum Library + { + HPPC, + TROVE, + FASTUTIL_OPEN, + FASTUTIL_LINKED, + MAHOUT + } + + static + { + try + { + BigramCountingBase.prepareData(); + } + catch (final Exception e) + { + throw new RuntimeException(e); + } + } + + @Setup + public void setUp() throws Exception + { + this.bc = new BigramCounting(); + } + + @Benchmark + public int timeLibrary() + { + + int count = 0; + + switch (this.library) + { + case HPPC: + count += this.bc.hppc(); + break; + case TROVE: + count += this.bc.trove(); + break; + case FASTUTIL_LINKED: + this.bc.fastutilLinkedOpenHashMap(); + break; + case FASTUTIL_OPEN: + count += this.bc.fastutilOpenHashMap(); + break; + case MAHOUT: + count += this.bc.mahoutCollections(); + break; + } + + // No need to return computation result because BigramCounting saves a guard (?). + return count; + } + + public static void main(final String[] args) throws RunnerException + { + BenchmarkSuiteRunner.runJmhBasicBenchmarkWithCommandLine(BenchmarkBigramCounting.class, args, 500, 1000); + } +} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkCollectionsSort.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkCollectionsSort.java new file mode 100644 index 000000000..8095a489f --- /dev/null +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkCollectionsSort.java @@ -0,0 +1,151 @@ +package com.carrotsearch.hppcrt.jmh; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.RunnerException; + +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; +import com.carrotsearch.hppcrt.sorting.IndirectComparator; +import com.carrotsearch.hppcrt.sorting.IndirectSort; +import com.google.common.collect.Lists; + +/** + * Benchmark {@link Collections#sort(java.util.List)}, in particular for differences + * in the new JDK 1.7 (TimSort). The point of this benchmark is to get the order + * of elements (their indexes), not an array or collection of sorted elements (!). + */ +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +public class BenchmarkCollectionsSort +{ + @Param("1000000") + public int size; + + private ArrayList data; + + //represent the initial index of data + private int[] indexes; + private int[] indexesClone; + private Integer[] indexesInteger; + + @Setup + public void setUp() throws Exception + { + + this.data = Lists.newArrayList(); + this.indexes = new int[this.size]; + this.indexesClone = new int[this.size]; + this.indexesInteger = new Integer[this.size]; + + for (int i = 0; i < this.size; i++) + { + this.data.add(Integer.toString(i)); + this.indexes[i] = i; + this.indexesInteger[i] = i; + } + + Collections.shuffle(this.data); + } + + /* + * + */ + @Benchmark + public int timeIndirectMergeSort() + { + int count = 0; + + final Object[] input = this.data.toArray(); + final int[] ordered = IndirectSort.mergesort(input, 0, input.length, new Comparator() + { + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public int compare(final Object o1, final Object o2) + { + return ((Comparable) o1).compareTo(o2); + } + }); + + count += ordered[0]; + + return count; + } + + /* + * + */ + @Benchmark + public int timeLegacySort() + { + System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); + return timeNewSort(); + } + + /* + * + */ + @Benchmark + public int timeNewSort() + { + final Integer[] indexesClone = this.indexesInteger.clone(); + + int count = 0; + + Arrays.sort(indexesClone, new Comparator() + { + final ArrayList dta = BenchmarkCollectionsSort.this.data; + + @Override + public int compare(final Integer o1, final Integer o2) + { + return this.dta.get(o1.intValue()).compareTo( + this.dta.get(o2.intValue())); + } + }); + count += indexesClone[0]; + + return count; + } + + /* + * + */ + @Benchmark + public int timeIndirectQuickSort() + { + int count = 0; + + //overwrite the same array, since it is modified in-place + System.arraycopy(this.indexes, 0, this.indexesClone, 0, this.indexes.length); + + IndirectSort.quicksort(0, this.indexesClone.length, new IndirectComparator() { + + final ArrayList dta = BenchmarkCollectionsSort.this.data; + + @Override + public int compare(final int o1, final int o2) + { + return this.dta.get(o1).compareTo(this.dta.get(o2)); + } + }, this.indexes); + + count += this.indexesClone[0]; + + return count; + } + + public static void main(final String[] args) throws RunnerException + { + BenchmarkSuiteRunner.runJmhBasicBenchmarkWithCommandLine(BenchmarkCollectionsSort.class, args, 500, 1000); + } +} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkContainsWithRemoved.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkContainsWithRemoved.java similarity index 65% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkContainsWithRemoved.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkContainsWithRemoved.java index 56d561db3..c37429dcb 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkContainsWithRemoved.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkContainsWithRemoved.java @@ -1,20 +1,30 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt.jmh; import java.util.Random; +import java.util.concurrent.TimeUnit; import org.apache.mahout.math.Arrays; - +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.RunnerException; + +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; import com.carrotsearch.hppcrt.DistributionGenerator; +import com.carrotsearch.hppcrt.Implementations; +import com.carrotsearch.hppcrt.MapImplementation; import com.carrotsearch.hppcrt.Util; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; /** * Create a large map of int keys, remove a fraction of the keys and query with half/half keys * and a some random values. */ -public class BenchmarkContainsWithRemoved extends SimpleBenchmark +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +public class BenchmarkContainsWithRemoved { /* Prepare some test data */ public int[] keys; @@ -37,8 +47,8 @@ public class BenchmarkContainsWithRemoved extends SimpleBenchmark }) public int size; - @Override - protected void setUp() throws Exception + @Setup + public void setUp() throws Exception { final Random rnd = new Random(0x11223344); @@ -74,24 +84,18 @@ protected void setUp() throws Exception } } - public int timeContains(final int reps) + @Benchmark + public int timeContains() { int count = 0; - for (int i = 0; i < reps; i++) - { - count += this.impl.containKeys(this.keys); - } - return count; - } - @Override - protected void tearDown() throws Exception - { - this.impl = null; + count += this.impl.containKeys(this.keys); + + return count; } - public static void main(final String[] args) + public static void main(final String[] args) throws RunnerException { - Runner.main(BenchmarkContainsWithRemoved.class, args); + BenchmarkSuiteRunner.runJmhBasicBenchmarkWithCommandLine(BenchmarkContainsWithRemoved.class, args, 500, 1000); } } \ No newline at end of file diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkHashCollisions.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkHashCollisions.java new file mode 100644 index 000000000..e5e079134 --- /dev/null +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkHashCollisions.java @@ -0,0 +1,208 @@ +package com.carrotsearch.hppcrt.jmh; + +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.RunnerException; + +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; +import com.carrotsearch.hppcrt.DistributionGenerator; +import com.carrotsearch.hppcrt.XorShiftRandom; +import com.carrotsearch.hppcrt.procedures.IntProcedure; +import com.carrotsearch.hppcrt.sets.IntOpenHashSet; + +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +public class BenchmarkHashCollisions +{ + + /* Prepare some test data */ + public IntOpenHashSet testSet; + + public IntOpenHashSet currentUnderTestSet; + + public IntOpenHashSet currentUnderTestSet2; + + public enum Distribution + { + RANDOM, LINEAR, LINEAR_DECREMENT, HIGHBITS; + } + + public enum Allocation + { + DEFAULT_SIZE, PREALLOCATED; + } + + @Param + public Allocation allocation; + + @Param + public Distribution distribution; + + @Param( + { + "5000000" + }) + public int size; + + public BenchmarkHashCollisions() { + // nothing + } + + @Setup + public void setUp() throws Exception + { + //Instead of this.size, fill up + //prepare testSet to be filled up to their specified load factor. + + this.testSet = new IntOpenHashSet(this.size); + + final DistributionGenerator gene = new DistributionGenerator(this.size, new XorShiftRandom(87955214455L)); + + int nextValue = -1; + + while (this.testSet.size() < this.testSet.capacity()) { + + if (this.distribution == Distribution.RANDOM) { + + nextValue = gene.RANDOM.getNext(); + } + else if (this.distribution == Distribution.LINEAR) { + + nextValue = gene.LINEAR.getNext(); + } + else if (this.distribution == Distribution.HIGHBITS) { + + nextValue = gene.HIGHBITS.getNext(); + } + else if (this.distribution == Distribution.LINEAR_DECREMENT) { + + nextValue = gene.LINEAR_DECREMENT.getNext(); + } + + this.testSet.add(nextValue); + } + + //Preallocate of not the tested hash containers + if (this.allocation == Allocation.DEFAULT_SIZE) { + + this.currentUnderTestSet = IntOpenHashSet.newInstance(); + this.currentUnderTestSet2 = IntOpenHashSet.newInstance(); + + } + else if (this.allocation == Allocation.PREALLOCATED) { + + this.currentUnderTestSet = IntOpenHashSet.newInstanceWithCapacity(this.size, IntOpenHashSet.DEFAULT_LOAD_FACTOR); + this.currentUnderTestSet2 = IntOpenHashSet.newInstanceWithCapacity(this.size, IntOpenHashSet.DEFAULT_LOAD_FACTOR); + } + } + + //Tests + /** + * Time the 'addAll' operation. + */ + @Benchmark + public int timeSet_AddAll() + { + int count = 0; + + this.currentUnderTestSet.clear(); + count += this.currentUnderTestSet.addAll(this.testSet); + + return count; + } + + @Benchmark + public int timeSet_AddAll_Successive() + { + int count = 0; + this.currentUnderTestSet.clear(); + this.currentUnderTestSet2.clear(); + count += this.currentUnderTestSet.addAll(this.testSet); + count += this.currentUnderTestSet2.addAll(this.currentUnderTestSet); + + return count; + } + + @Benchmark + public int timeSet_Direct_iteration_add_all() + { + int count = 0; + + this.currentUnderTestSet.clear(); + + final int[] testSetKeys = this.testSet.keys; + + for (int j = 0; j < testSetKeys.length; j++) { + + if (testSetKeys[j] != 0) { + + this.currentUnderTestSet.add(testSetKeys[j]); + } + } + + count += this.currentUnderTestSet.size(); + + return count; + } + + @Benchmark + public int timeSet_Direct_iteration_reversed_add_all() + { + int count = 0; + + this.currentUnderTestSet.clear(); + + final int[] testSetKeys = this.testSet.keys; + + for (int j = testSetKeys.length - 1; j >= 0; j--) { + + if (testSetKeys[j] != 0) { + + this.currentUnderTestSet.add(testSetKeys[j]); + } + } + + count += this.currentUnderTestSet.size(); + + return count; + } + + @Benchmark + public int timeSet_ForEach_add_all() + { + final IntProcedure addAllProcedure = new IntProcedure() { + + @Override + public final void apply(final int value) { + + BenchmarkHashCollisions.this.currentUnderTestSet.add(value); + } + }; + + int count = 0; + + this.currentUnderTestSet.clear(); + + this.testSet.forEach(addAllProcedure); + + count += this.currentUnderTestSet.size(); + + return count; + } + + /** + * Running main + * @param args + * @throws RunnerException + */ + public static void main(final String[] args) throws RunnerException + { + BenchmarkSuiteRunner.runJmhBasicBenchmarkWithCommandLine(BenchmarkHashCollisions.class, args, 500, 1000); + } +} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkPopCnt.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkPopCnt.java new file mode 100644 index 000000000..9545ae68f --- /dev/null +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkPopCnt.java @@ -0,0 +1,142 @@ +package com.carrotsearch.hppcrt.jmh; + +import java.util.Arrays; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.RunnerException; + +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; +import com.carrotsearch.hppcrt.BroadWord; + +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +public class BenchmarkPopCnt +{ + long[] seq; + + @Param + public Distribution distribution; + + public static enum Distribution + { + ZEROS, + FULL, + RANDOM, + ONEBIT + } + + @Setup + public void setUp() throws Exception + { + this.seq = new long[1000000]; + + final Random rnd = new Random(0xdeadbeef); + switch (this.distribution) { + case ZEROS: + break; + case FULL: + Arrays.fill(this.seq, -1); + break; + case RANDOM: + for (int i = 0; i < this.seq.length; i++) { + this.seq[i] = rnd.nextLong(); + } + break; + case ONEBIT: + for (int i = 0; i < this.seq.length; i++) { + this.seq[i] = 1L << rnd.nextInt(64); + } + break; + } + } + + @Benchmark + public int timeLongBitCount() { + int v = 0; + + for (int j = 0; j < this.seq.length; j++) { + v += Long.bitCount(this.seq[j]); + } + + return v; + } + + @Benchmark + public int timeHdPopCnd() { + int v = 0; + + for (int j = 0; j < this.seq.length; j++) { + v += BenchmarkPopCnt.hdBitCount(this.seq[j]); + } + + return v; + } + + @Benchmark + public int timeRank9() { + int v = 0; + + for (int j = 0; j < this.seq.length; j++) { + v += BenchmarkPopCnt.rank9(this.seq[j]); + } + + return v; + } + + @Benchmark + public int timeNaivePopCnt() { + int v = 0; + + for (int j = 0; j < this.seq.length; j++) { + v += BenchmarkPopCnt.naivePopCnt(this.seq[j]); + } + + return v; + } + + // + + private static int naivePopCnt(long x) { + int cnt = 0; + while (x != 0) { + if (((x >>>= 1) & 1) != 0L) { + cnt++; + } + } + return cnt; + } + + private static int hdBitCount(long i) { + // HD, Figure 5-14 + i = i - ((i >>> 1) & 0x5555555555555555L); + i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L); + i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL; + i = i + (i >>> 8); + i = i + (i >>> 16); + i = i + (i >>> 32); + return (int) i & 0x7f; + } + + private static int rank9(long x) { + // Step 0 leaves in each pair of bits the number of ones originally contained in that pair: + x = x - ((x & 0xAAAAAAAAAAAAAAAAL) >>> 1); + // Step 1, idem for each nibble: + x = (x & 0x3333333333333333L) + ((x >>> 2) & 0x3333333333333333L); + // Step 2, idem for each byte: + x = (x + (x >>> 4)) & 0x0F0F0F0F0F0F0F0FL; + // Multiply to sum them all into the high byte, and return the high byte: + return (int) ((x * BroadWord.L8_L) >>> 56); + } + + public static void main(final String[] args) throws RunnerException + { + BenchmarkSuiteRunner.runJmhBasicBenchmarkWithCommandLine(BenchmarkPopCnt.class, args, 500, 1000); + } +} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkPut.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkPut.java similarity index 60% rename from hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkPut.java rename to hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkPut.java index 8ca1a6add..c415bcc3e 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/caliper/BenchmarkPut.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jmh/BenchmarkPut.java @@ -1,15 +1,27 @@ -package com.carrotsearch.hppcrt.caliper; +package com.carrotsearch.hppcrt.jmh; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.RunnerException; + +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; import com.carrotsearch.hppcrt.DistributionGenerator; +import com.carrotsearch.hppcrt.Implementations; +import com.carrotsearch.hppcrt.MapImplementation; import com.carrotsearch.hppcrt.XorShiftRandom; -import com.google.caliper.Param; -import com.google.caliper.Runner; -import com.google.caliper.SimpleBenchmark; /** * Benchmark putting a given number of integers into a hashmap. */ -public class BenchmarkPut extends SimpleBenchmark +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +public class BenchmarkPut { /* Prepare some test data */ public int[] keys; @@ -36,8 +48,8 @@ public enum Distribution /* * */ - @Override - protected void setUp() throws Exception + @Setup + public void setUp() throws Exception { // Our tested implementation, uses preallocation this.impl = this.implementation.getInstance(this.size); @@ -67,19 +79,19 @@ protected void setUp() throws Exception /** * Time the 'put' operation. */ - public int timePut(final int reps) + @Benchmark + public int timePut() { int count = 0; - for (int i = 0; i < reps; i++) - { - this.impl.clear(); - count += this.impl.putAll(this.keys, this.keys); - } + + this.impl.clear(); + count += this.impl.putAll(this.keys, this.keys); + return count; } - public static void main(final String[] args) + public static void main(final String[] args) throws RunnerException { - Runner.main(BenchmarkPut.class, args); + BenchmarkSuiteRunner.runJmhBasicBenchmarkWithCommandLine(BenchmarkPut.class, args, 500, 1000); } } \ No newline at end of file diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jub/HashMapBenchmark.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jub/HashMapBenchmark.java deleted file mode 100644 index 56d38acd6..000000000 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/jub/HashMapBenchmark.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.carrotsearch.hppcrt.jub; - -import java.util.HashMap; -import java.util.Random; - -import org.junit.*; - -import com.carrotsearch.hppcrt.maps.ObjectObjectOpenHashMap; -import com.carrotsearch.junitbenchmarks.AbstractBenchmark; - -/** - * A micro-benchmark test case for comparing {@link HashMap} against - * {@link ObjectObjectOpenHashMap}. - */ -public class HashMapBenchmark extends AbstractBenchmark -{ - private static HashMap jre = new HashMap(); - - private static int COUNT = 1000000; - private static Integer[] numbers = new Integer[HashMapBenchmark.COUNT]; - - /* */ - @BeforeClass - public static void createTestSequence() - { - final Random rnd = new Random(0x11223344); - for (int i = 0; i < HashMapBenchmark.COUNT; i++) - HashMapBenchmark.numbers[i] = rnd.nextInt(); - } - - /* */ - @Before - public void before() - { - HashMapBenchmark.jre.clear(); - } - - /* */ - @Test - public void testMultipleOperations() throws Exception - { - for (int r = 0; r < 2; r++) - { - for (int i = 0; i < HashMapBenchmark.numbers.length - r; i++) - { - if ((HashMapBenchmark.numbers[i].intValue() & 0x1) == 0) - HashMapBenchmark.jre.remove(HashMapBenchmark.numbers[i + r]); - else - HashMapBenchmark.jre.put(HashMapBenchmark.numbers[i], HashMapBenchmark.numbers[i]); - } - } - HashMapBenchmark.jre.clear(); - } -} diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/BenchmarkHashContainersSuite.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/BenchmarkHashContainersSuite.java index aab5e55ab..50388b421 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/BenchmarkHashContainersSuite.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/BenchmarkHashContainersSuite.java @@ -1,21 +1,11 @@ package com.carrotsearch.hppcrt.misc; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; -import com.carrotsearch.hppcrt.Util; -import com.carrotsearch.hppcrt.caliper.BenchmarkContainsWithRemoved; -import com.carrotsearch.hppcrt.caliper.BenchmarkHashCollisionsAddAllSuccessive; -import com.carrotsearch.hppcrt.caliper.BenchmarkHashCollisionsDirectIterationAddAll; -import com.carrotsearch.hppcrt.caliper.BenchmarkHashCollisionsDirectIterationReversedAddAll; -import com.carrotsearch.hppcrt.caliper.BenchmarkHashCollisionsForEachAddAll; -import com.carrotsearch.hppcrt.caliper.BenchmarkPut; -import com.carrotsearch.hppcrt.caliper.BenchmarkHashCollisionsAddAll; -import com.google.caliper.Benchmark; -import com.google.caliper.Runner; -import com.google.common.collect.Lists; -import com.google.common.collect.ObjectArrays; +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; +import com.carrotsearch.hppcrt.jmh.BenchmarkContainsWithRemoved; +import com.carrotsearch.hppcrt.jmh.BenchmarkHashCollisions; +import com.carrotsearch.hppcrt.jmh.BenchmarkPut; /** * Runs the suite of benchmarks about hash containers @@ -23,110 +13,15 @@ public class BenchmarkHashContainersSuite { private final static Class[] ALL_BENCHMARKS = new Class[] - { - BenchmarkHashCollisionsAddAll.class, - BenchmarkHashCollisionsAddAllSuccessive.class, - BenchmarkHashCollisionsDirectIterationAddAll.class, - BenchmarkHashCollisionsDirectIterationReversedAddAll.class, - BenchmarkHashCollisionsForEachAddAll.class, - BenchmarkPut.class, - BenchmarkContainsWithRemoved.class, - HppcMapSyntheticBench.class - }; - - public static void main(final String[] args) throws Exception - { - String fullArgString = ""; - - for (final String strInd : args) { - - fullArgString += strInd + " "; - } - - final String[] parsedArgs = fullArgString.split("---"); - - //argument check - if (parsedArgs.length != 3) - { - System.out.println("Args: --- --- "); - System.out.println("Known benchmark classes: "); - - for (final Class clz : BenchmarkHashContainersSuite.ALL_BENCHMARKS) - { - System.out.println("\t" + clz.getName()); - } - return; - } - - //list of arguments - final ArrayList argsListCaliper = new ArrayList(); - - for (final String arg : parsedArgs[1].trim().split("\\s")) { - - if (!arg.trim().isEmpty()) { - - argsListCaliper.add(arg.trim()); - } - } - - final ArrayList argsListOther = new ArrayList(); - - for (final String arg : parsedArgs[args.length - 1].trim().split("\\s")) { - - argsListOther.add(arg.trim()); - } - - final List> classesCaliper = new ArrayList>(); - final List> classesOther = new ArrayList>(); - - //enumerate - for (final Class clz : BenchmarkHashContainersSuite.ALL_BENCHMARKS) { - - if (Benchmark.class.isAssignableFrom(clz)) { - classesCaliper.add((Class) clz); - } - else { - classesOther.add(clz); - } - - } //end for - - Util.printSystemInfo("Benchmark suite for hash containers starting."); - BenchmarkHashContainersSuite.runBenchmarks(classesCaliper, argsListCaliper.toArray(new String[argsListCaliper.size()]), - classesOther, argsListOther.toArray(new String[argsListOther.size()])); - } + BenchmarkHashCollisions.class, + BenchmarkPut.class, + BenchmarkContainsWithRemoved.class, + HppcMapSyntheticBench.class + }; - /** - * - */ - private static void runBenchmarks(final List> caliperClasses, final String[] argsCaliper, - final List> otherClasses, final String[] argsOther - ) throws Exception + public static void main(final String[] args) throws Exception { - int i = 0; - - final int totalSize = caliperClasses.size() + otherClasses.size(); - - for (final Class clz : caliperClasses) - { - Util.printHeader(clz.getSimpleName() + " (" + (++i) + "/" + totalSize + ")"); - try { - new Runner().run(ObjectArrays.concat(argsCaliper, clz.getName())); - } - catch (final Exception e) { - - System.out.println("Benchmark aborted with error: " + e); - } - } - - for (final Class clz : otherClasses) - { - Util.printHeader(clz.getSimpleName() + " (" + (++i) + "/" + totalSize + ")"); - - final Method method = clz.getDeclaredMethod("main", String[].class); - - method.invoke(null, new Object[] { argsOther }); - } + BenchmarkSuiteRunner.runMain(Arrays.asList(BenchmarkHashContainersSuite.ALL_BENCHMARKS), args); } } diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcArraysBench.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcArraysBench.java index 255b4da1a..42f6670e6 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcArraysBench.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcArraysBench.java @@ -3,6 +3,7 @@ import java.util.Comparator; import java.util.Random; +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; import com.carrotsearch.hppcrt.LongArrays; import com.carrotsearch.hppcrt.XorShiftRandom; @@ -205,19 +206,17 @@ public void runBenchArrays(final int nbElements) */ public static void main(final String[] args) { - if (args.length != 1 || !args[0].contains("--warmup=")) - { - System.out.println("Usage : " + HppcArraysBench.class.getName() + " --warmup=[nb warmup runs]"); - } - else - { - final int nbWarmup = new Integer(args[0].split("--warmup=")[1]); + final BenchmarkSuiteRunner.BenchmarkOptions opts = new BenchmarkSuiteRunner.BenchmarkOptions(); - final HppcArraysBench testClass = new HppcArraysBench(nbWarmup); + BenchmarkSuiteRunner.parseCommonArguments(args, opts); - System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC ARRAYS BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + final int nbWarmup = opts.nbWarmups; - testClass.runBenchArrays(HppcArraysBench.COUNT); - } + final HppcArraysBench testClass = new HppcArraysBench(nbWarmup); + + System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC ARRAYS BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + + testClass.runBenchArrays(HppcArraysBench.COUNT); } + } diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcHeapsSyntheticBench.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcHeapsSyntheticBench.java index e60790c64..499fb7ed8 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcHeapsSyntheticBench.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcHeapsSyntheticBench.java @@ -3,6 +3,7 @@ import java.util.Comparator; import java.util.Random; +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; import com.carrotsearch.hppcrt.Util; import com.carrotsearch.hppcrt.XorShiftRandom; import com.carrotsearch.hppcrt.heaps.LongHeapPriorityQueue; @@ -278,7 +279,6 @@ public void runIndexedPrioQueueLongObjects(final String additionalInfo, final Ob //don't make things too easy, shuffle it so the bench do some pointer chasing in memory... Util.shuffle(referenceArray, this.prng); - while (nbWarmups <= this.nbWarmupsRuns) { pq.clear(); @@ -393,7 +393,6 @@ public void runPrioQueuePrimitiveLong(final String additionalInfo, final LongHea this.prng.setSeed(HppcHeapsSyntheticBench.RANDOM_SEED); - while (nbWarmups <= this.nbWarmupsRuns) { pq.clear(); @@ -510,12 +509,12 @@ public boolean apply(final long value) } //end while System.out - .format(">>>> BENCH: HPPC Prio queues (long), (%s), %d elements inserted, with filtered out odd values in (heap = %d removed values in %f ms / IndexedHeap = %d removed values in %f ms) (dummy: %d)\n", - additionalInfo, - initialSize, - nbRemovedHeap, (tAfterHeap - tBeforeHeap) / 1e6, - nbRemovedIndexedHeap, (tAfterIndexedHeap - tBeforeIndexedHeap) / 1e6, - sum); + .format(">>>> BENCH: HPPC Prio queues (long), (%s), %d elements inserted, with filtered out odd values in (heap = %d removed values in %f ms / IndexedHeap = %d removed values in %f ms) (dummy: %d)\n", + additionalInfo, + initialSize, + nbRemovedHeap, (tAfterHeap - tBeforeHeap) / 1e6, + nbRemovedIndexedHeap, (tAfterIndexedHeap - tBeforeIndexedHeap) / 1e6, + sum); } /** @@ -594,12 +593,12 @@ public boolean apply(final long value) } //end while System.out - .format(">>>> BENCH: HPPC Prio queues (long), (%s), %d elements inserted, with keeping odd values in (heap = %d kept values in %f ms / IndexedHeap = %d kept values in %f ms) (dummy: %d)\n", - additionalInfo, - initialSize, - nbKeptHeap, (tAfterHeap - tBeforeHeap) / 1e6, - nbKeptIndexedHeap, (tAfterIndexedHeap - tBeforeIndexedHeap) / 1e6, - sum); + .format(">>>> BENCH: HPPC Prio queues (long), (%s), %d elements inserted, with keeping odd values in (heap = %d kept values in %f ms / IndexedHeap = %d kept values in %f ms) (dummy: %d)\n", + additionalInfo, + initialSize, + nbKeptHeap, (tAfterHeap - tBeforeHeap) / 1e6, + nbKeptIndexedHeap, (tAfterIndexedHeap - tBeforeIndexedHeap) / 1e6, + sum); } /** @@ -676,7 +675,6 @@ public void runPrioQueueLongObjects(final String additionalInfo, final ObjectHea //don't make things too easy, shuffle it so the bench do some pointer chasing in memory... Util.shuffle(referenceArray, this.prng); - while (nbWarmups <= this.nbWarmupsRuns) { pq.clear(); @@ -885,19 +883,17 @@ public int compare(final ComparableLong o1, final ComparableLong o2) */ public static void main(final String[] args) { - if (args.length != 1 || !args[0].contains("--warmup=")) - { - System.out.println("Usage : " + HppcHeapsSyntheticBench.class.getName() + " --warmup=[nb warmup runs]"); - } - else - { - final int nbWarmup = new Integer(args[0].split("--warmup=")[1]); + final BenchmarkSuiteRunner.BenchmarkOptions opts = new BenchmarkSuiteRunner.BenchmarkOptions(); - final HppcHeapsSyntheticBench testClass = new HppcHeapsSyntheticBench(nbWarmup); + BenchmarkSuiteRunner.parseCommonArguments(args, opts); - System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC HEAPS SYNTHETIC BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + final int nbWarmup = opts.nbWarmups; + + final HppcHeapsSyntheticBench testClass = new HppcHeapsSyntheticBench(nbWarmup); + + System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC HEAPS SYNTHETIC BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + + testClass.runBenchHeaps(HppcHeapsSyntheticBench.COUNT); - testClass.runBenchHeaps(HppcHeapsSyntheticBench.COUNT); - } } } diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcListSyntheticBench.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcListSyntheticBench.java index 9ac3c2624..69ddc6fe7 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcListSyntheticBench.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcListSyntheticBench.java @@ -1,10 +1,9 @@ package com.carrotsearch.hppcrt.misc; import java.util.Comparator; - - import java.util.Random; +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; import com.carrotsearch.hppcrt.LongIndexedContainer; import com.carrotsearch.hppcrt.XorShiftRandom; import com.carrotsearch.hppcrt.cursors.LongCursor; @@ -646,7 +645,8 @@ public void runBenchList(final int nbElements) //Linked-list : System.gc(); - runListIterationBench("LinkedList, get() is O(N), direct iteration is out of order !", new LongLinkedList((int) (HppcListSyntheticBench.COUNT * 1e-2)), (int) (HppcListSyntheticBench.COUNT * 1e-2), + runListIterationBench("LinkedList, get() is O(N), direct iteration is out of order !", new LongLinkedList((int) (HppcListSyntheticBench.COUNT * 1e-2)), + (int) (HppcListSyntheticBench.COUNT * 1e-2), this.nbWarmupsRuns); System.gc(); runListPrimitiveLong("LinkedList", new LongLinkedList(nbElements), nbElements, this.nbWarmupsRuns); @@ -670,20 +670,18 @@ public void runBenchList(final int nbElements) public static void main(final String[] args) { - if (args.length != 1 || !args[0].contains("--warmup=")) - { - System.out.println("Usage : " + HppcListSyntheticBench.class.getName() + " --warmup=[nb warmup runs]"); - } - else - { - final int nbWarmup = new Integer(args[0].split("--warmup=")[1]); + final BenchmarkSuiteRunner.BenchmarkOptions opts = new BenchmarkSuiteRunner.BenchmarkOptions(); - final HppcListSyntheticBench testClass = new HppcListSyntheticBench(nbWarmup); + BenchmarkSuiteRunner.parseCommonArguments(args, opts); - System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC LISTS SYNTHETIC BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + final int nbWarmup = opts.nbWarmups; + + final HppcListSyntheticBench testClass = new HppcListSyntheticBench(nbWarmup); + + System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC LISTS SYNTHETIC BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + + testClass.runBenchList(HppcListSyntheticBench.COUNT); - testClass.runBenchList(HppcListSyntheticBench.COUNT); - } } } diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcMapSyntheticBench.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcMapSyntheticBench.java index d511e5ada..55778cbcf 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcMapSyntheticBench.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcMapSyntheticBench.java @@ -1,16 +1,24 @@ package com.carrotsearch.hppcrt.misc; -import java.util.Arrays; -import java.util.Comparator; import java.util.Random; -import com.carrotsearch.hppcrt.*; +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; +import com.carrotsearch.hppcrt.DistributionGenerator; import com.carrotsearch.hppcrt.DistributionGenerator.Generator; -import com.carrotsearch.hppcrt.lists.*; -import com.carrotsearch.hppcrt.maps.*; -import com.carrotsearch.hppcrt.procedures.*; -import com.carrotsearch.hppcrt.cursors.*; -import com.carrotsearch.hppcrt.strategies.*; +import com.carrotsearch.hppcrt.IntLongMap; +import com.carrotsearch.hppcrt.ObjectLongMap; +import com.carrotsearch.hppcrt.Util; +import com.carrotsearch.hppcrt.XorShiftRandom; +import com.carrotsearch.hppcrt.cursors.IntLongCursor; +import com.carrotsearch.hppcrt.lists.IntArrayList; +import com.carrotsearch.hppcrt.lists.LongArrayList; +import com.carrotsearch.hppcrt.lists.ObjectArrayList; +import com.carrotsearch.hppcrt.maps.IntLongOpenHashMap; +import com.carrotsearch.hppcrt.maps.ObjectLongOpenCustomHashMap; +import com.carrotsearch.hppcrt.maps.ObjectLongOpenHashMap; +import com.carrotsearch.hppcrt.maps.ObjectLongOpenIdentityHashMap; +import com.carrotsearch.hppcrt.procedures.LongProcedure; +import com.carrotsearch.hppcrt.strategies.ObjectHashingStrategy; public final class HppcMapSyntheticBench { @@ -776,87 +784,83 @@ private Generator getGenerator(final Distribution disKind, final int size) */ public static void main(final String[] args) { + final BenchmarkSuiteRunner.BenchmarkOptions opts = new BenchmarkSuiteRunner.BenchmarkOptions(); - if (args.length != 1 || !args[0].contains("--warmup=")) - { + BenchmarkSuiteRunner.parseCommonArguments(args, opts); - System.out.println("Usage : " + HppcMapSyntheticBench.class.getName() + " --warmup=[nb warmup runs]"); - } - else - { - final int nbWarmup = new Integer(args[0].split("--warmup=")[1]); + final int nbWarmup = opts.nbWarmups; - final HppcMapSyntheticBench testClass = new HppcMapSyntheticBench(nbWarmup); + final HppcMapSyntheticBench testClass = new HppcMapSyntheticBench(nbWarmup); - //Map synthetic bench - System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC HASH MAPS SYNTHETIC BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + //Map synthetic bench + System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC HASH MAPS SYNTHETIC BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); - //map iteration benchs - testClass.runMapIterationBench(); - System.gc(); + //map iteration benchs + testClass.runMapIterationBench(); + System.gc(); - if (HppcMapSyntheticBench.RUN_PRIMITIVES) { - System.out.println("\n"); - testClass.runMapSyntheticBenchPrimitives(MAP_LOOKUP_TEST.MOSTLY_TRUE); - System.gc(); - } + if (HppcMapSyntheticBench.RUN_PRIMITIVES) { + System.out.println("\n"); + testClass.runMapSyntheticBenchPrimitives(MAP_LOOKUP_TEST.MOSTLY_TRUE); + System.gc(); + } - if (HppcMapSyntheticBench.RUN_IDENTITY) { - System.out.println("\n"); + if (HppcMapSyntheticBench.RUN_IDENTITY) { + System.out.println("\n"); - testClass.runMapIdentityObjectLong("ObjectLongOpenIdentityHashMap", - ObjectLongOpenIdentityHashMap. newInstance(HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR), - HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR, MAP_LOOKUP_TEST.MOSTLY_TRUE); - System.gc(); - } + testClass.runMapIdentityObjectLong("ObjectLongOpenIdentityHashMap", + ObjectLongOpenIdentityHashMap. newInstance(HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR), + HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR, MAP_LOOKUP_TEST.MOSTLY_TRUE); + System.gc(); + } - if (HppcMapSyntheticBench.RUN_INTEGERS) { - System.out.println("\n"); - testClass.runMapSyntheticBenchComparableInt(MAP_LOOKUP_TEST.MOSTLY_TRUE); - System.gc(); - } + if (HppcMapSyntheticBench.RUN_INTEGERS) { + System.out.println("\n"); + testClass.runMapSyntheticBenchComparableInt(MAP_LOOKUP_TEST.MOSTLY_TRUE); + System.gc(); + } - if (HppcMapSyntheticBench.RUN_PRIMITIVES) { - System.out.println("\n\n"); - testClass.runMapSyntheticBenchPrimitives(MAP_LOOKUP_TEST.MIXED); - System.gc(); - } + if (HppcMapSyntheticBench.RUN_PRIMITIVES) { + System.out.println("\n\n"); + testClass.runMapSyntheticBenchPrimitives(MAP_LOOKUP_TEST.MIXED); + System.gc(); + } - if (HppcMapSyntheticBench.RUN_IDENTITY) { - System.out.println("\n"); + if (HppcMapSyntheticBench.RUN_IDENTITY) { + System.out.println("\n"); - testClass.runMapIdentityObjectLong("ObjectLongOpenIdentityHashMap", - ObjectLongOpenIdentityHashMap. newInstance(HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR), - HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR, MAP_LOOKUP_TEST.MIXED); - System.gc(); - } + testClass.runMapIdentityObjectLong("ObjectLongOpenIdentityHashMap", + ObjectLongOpenIdentityHashMap. newInstance(HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR), + HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR, MAP_LOOKUP_TEST.MIXED); + System.gc(); + } - if (HppcMapSyntheticBench.RUN_INTEGERS) { - System.out.println("\n"); - testClass.runMapSyntheticBenchComparableInt(MAP_LOOKUP_TEST.MIXED); - System.gc(); - } + if (HppcMapSyntheticBench.RUN_INTEGERS) { + System.out.println("\n"); + testClass.runMapSyntheticBenchComparableInt(MAP_LOOKUP_TEST.MIXED); + System.gc(); + } - if (HppcMapSyntheticBench.RUN_PRIMITIVES) { - System.out.println("\n\n"); - testClass.runMapSyntheticBenchPrimitives(MAP_LOOKUP_TEST.MOSTLY_FALSE); - System.gc(); - } + if (HppcMapSyntheticBench.RUN_PRIMITIVES) { + System.out.println("\n\n"); + testClass.runMapSyntheticBenchPrimitives(MAP_LOOKUP_TEST.MOSTLY_FALSE); + System.gc(); + } - if (HppcMapSyntheticBench.RUN_IDENTITY) { - System.out.println("\n"); + if (HppcMapSyntheticBench.RUN_IDENTITY) { + System.out.println("\n"); - testClass.runMapIdentityObjectLong("ObjectLongOpenIdentityHashMap", - ObjectLongOpenIdentityHashMap. newInstance(HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR), - HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR, MAP_LOOKUP_TEST.MOSTLY_FALSE); - System.gc(); - } + testClass.runMapIdentityObjectLong("ObjectLongOpenIdentityHashMap", + ObjectLongOpenIdentityHashMap. newInstance(HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR), + HppcMapSyntheticBench.COUNT, ObjectLongOpenHashMap.DEFAULT_LOAD_FACTOR, MAP_LOOKUP_TEST.MOSTLY_FALSE); + System.gc(); + } - if (HppcMapSyntheticBench.RUN_INTEGERS) { - System.out.println("\n"); - testClass.runMapSyntheticBenchComparableInt(MAP_LOOKUP_TEST.MOSTLY_FALSE); - System.gc(); - } + if (HppcMapSyntheticBench.RUN_INTEGERS) { + System.out.println("\n"); + testClass.runMapSyntheticBenchComparableInt(MAP_LOOKUP_TEST.MOSTLY_FALSE); + System.gc(); } + } } diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcSortSyntheticBench.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcSortSyntheticBench.java index 9bda87714..11ebad9fc 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcSortSyntheticBench.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/HppcSortSyntheticBench.java @@ -4,6 +4,7 @@ import java.util.Comparator; import java.util.Random; +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; import com.carrotsearch.hppcrt.Util; import com.carrotsearch.hppcrt.XorShiftRandom; import com.carrotsearch.hppcrt.sorting.DoubleSort; @@ -427,20 +428,17 @@ public void runBenchSort(final int nbElements) */ public static void main(final String[] args) { + final BenchmarkSuiteRunner.BenchmarkOptions opts = new BenchmarkSuiteRunner.BenchmarkOptions(); - if (args.length != 1 || !args[0].contains("--warmup=")) - { - System.out.println("Usage : " + HppcSortSyntheticBench.class.getName() + " --warmup=[nb warmup runs]"); - } - else - { - final int nbWarmup = new Integer(args[0].split("--warmup=")[1]); + BenchmarkSuiteRunner.parseCommonArguments(args, opts); - final HppcSortSyntheticBench testClass = new HppcSortSyntheticBench(nbWarmup); + final int nbWarmup = opts.nbWarmups; - System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC SORTING SYNTHETIC BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + final HppcSortSyntheticBench testClass = new HppcSortSyntheticBench(nbWarmup); + + System.out.println(String.format(">>>>>>>>>>>>>>>>>>>> HPPC SORTING SYNTHETIC BENCH with %d warmup runs ... <<<<<<<<<<<<<<<<<<<<\n", nbWarmup)); + + testClass.runBenchSort(HppcSortSyntheticBench.COUNT); - testClass.runBenchSort(HppcSortSyntheticBench.COUNT); - } } } diff --git a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/SyntheticBenchmarkSuite.java b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/SyntheticBenchmarkSuite.java index 64c5d7037..cc01a5b02 100644 --- a/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/SyntheticBenchmarkSuite.java +++ b/hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/misc/SyntheticBenchmarkSuite.java @@ -1,10 +1,7 @@ package com.carrotsearch.hppcrt.misc; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import com.carrotsearch.hppcrt.Util; +import java.util.Arrays; +import com.carrotsearch.hppcrt.BenchmarkSuiteRunner; /** * Runs the suite of benchmarks about hash containers @@ -16,73 +13,15 @@ public class SyntheticBenchmarkSuite */ private final static Class[] ALL_BENCHMARKS = new Class[] { - HppcArraysBench.class, - HppcSortSyntheticBench.class, - HppcListSyntheticBench.class, - HppcHeapsSyntheticBench.class, - HppcMapSyntheticBench.class + HppcArraysBench.class, + HppcSortSyntheticBench.class, + HppcListSyntheticBench.class, + HppcHeapsSyntheticBench.class, + HppcMapSyntheticBench.class }; public static void main(final String[] args) throws Exception { - String fullArgString = ""; - - for (final String strInd : args) { - - fullArgString += strInd + " "; - } - - final String[] parsedArgs = fullArgString.split("---"); - - //argument check - if (parsedArgs.length != 2) - { - System.out.println("Args: --- "); - System.out.println("Known benchmark classes: "); - - for (final Class clz : SyntheticBenchmarkSuite.ALL_BENCHMARKS) - { - System.out.println("\t" + clz.getName()); - } - return; - } - - final ArrayList argsListOther = new ArrayList(); - - for (final String arg : parsedArgs[args.length - 1].trim().split("\\s")) { - - argsListOther.add(arg.trim()); - } - - final List> classesOther = new ArrayList>(); - - //enumerate - for (final Class clz : SyntheticBenchmarkSuite.ALL_BENCHMARKS) { - - classesOther.add(clz); - - } //end for - - Util.printSystemInfo("Synthetic Benchmark Suite for HPPC-RT starting."); - SyntheticBenchmarkSuite.runBenchmarks(classesOther, argsListOther.toArray(new String[argsListOther.size()])); - } - - /** - * - */ - private static void runBenchmarks(final List> otherClasses, final String[] argsOther) throws Exception - { - int i = 0; - - final int totalSize = otherClasses.size(); - - for (final Class clz : otherClasses) - { - Util.printHeader(clz.getSimpleName() + " (" + (++i) + "/" + totalSize + ")"); - - final Method method = clz.getDeclaredMethod("main", String[].class); - - method.invoke(null, new Object[] { argsOther }); - } + BenchmarkSuiteRunner.runMain(Arrays.asList(SyntheticBenchmarkSuite.ALL_BENCHMARKS), args); } } diff --git a/hppcrt-templateprocessor/pom.xml b/hppcrt-templateprocessor/pom.xml index bc3afd0f5..9b68b2d9e 100644 --- a/hppcrt-templateprocessor/pom.xml +++ b/hppcrt-templateprocessor/pom.xml @@ -29,6 +29,12 @@ velocity 1.7 + + + org.apache.velocity + velocity-tools + 2.0 + diff --git a/pom.xml b/pom.xml index 5b1e96d21..7f672ada3 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ com.google.guava guava - 14.0.1 + 18.0 @@ -140,7 +140,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 + 1.6 @@ -161,6 +161,12 @@ + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + org.apache.maven.plugins