aboutsummaryrefslogtreecommitdiffstats
path: root/guava-tests/benchmark/com/google/common/hash
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/benchmark/com/google/common/hash')
-rw-r--r--guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java99
-rw-r--r--guava-tests/benchmark/com/google/common/hash/HashBenchmark.java92
-rw-r--r--guava-tests/benchmark/com/google/common/hash/HashFunctionBenchmark.java87
-rw-r--r--guava-tests/benchmark/com/google/common/hash/MessageDigestAlgorithmBenchmark.java111
-rw-r--r--guava-tests/benchmark/com/google/common/hash/MessageDigestCreationBenchmark.java60
5 files changed, 0 insertions, 449 deletions
diff --git a/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java b/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java
deleted file mode 100644
index 28dba53..0000000
--- a/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2012 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.hash;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-
-import java.util.Random;
-import java.util.zip.Adler32;
-import java.util.zip.CRC32;
-import java.util.zip.Checksum;
-
-/**
- * Benchmarks for comparing {@link Checksum}s and {@link HashFunction}s that wrap {@link Checksum}s.
- *
- * <p>Parameters for the benchmark are: <ul> <li>size: The length of the byte array to hash. </ul>
- *
- * @author Colin Decker
- */
-public class ChecksumBenchmark extends SimpleBenchmark {
-
- // Use a constant seed for all of the benchmarks to ensure apples to apples comparisons.
- private static final int RANDOM_SEED = new Random().nextInt();
-
- @Param({"10", "1000", "100000", "1000000"})
- private int size;
-
- private byte[] testBytes;
-
- @Override
- public void setUp() {
- testBytes = new byte[size];
- new Random(RANDOM_SEED).nextBytes(testBytes);
- }
-
- // CRC32
-
- public byte timeCrc32HashFunction(int reps) {
- return runHashFunction(reps, Hashing.crc32());
- }
-
- public byte timeCrc32Checksum(int reps) throws Exception {
- byte result = 0x01;
- for (int i = 0; i < reps; i++) {
- CRC32 checksum = new CRC32();
- checksum.update(testBytes);
- result ^= checksum.getValue();
- }
- return result;
- }
-
- // Adler32
-
- public byte timeAdler32HashFunction(int reps) {
- return runHashFunction(reps, Hashing.adler32());
- }
-
- public byte timeAdler32Checksum(int reps) throws Exception {
- byte result = 0x01;
- for (int i = 0; i < reps; i++) {
- Adler32 checksum = new Adler32();
- checksum.update(testBytes);
- result ^= checksum.getValue();
- }
- return result;
- }
-
- // Helpers + main
-
- private byte runHashFunction(int reps, HashFunction hashFunction) {
- byte result = 0x01;
- // Trick the JVM to prevent it from using the hash function non-polymorphically
- result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
- result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
- for (int i = 0; i < reps; i++) {
- result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
- }
- return result;
- }
-
- public static void main(String[] args) {
- Runner.main(ChecksumBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/hash/HashBenchmark.java b/guava-tests/benchmark/com/google/common/hash/HashBenchmark.java
deleted file mode 100644
index 2027218..0000000
--- a/guava-tests/benchmark/com/google/common/hash/HashBenchmark.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.hash;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-
-import java.util.Random;
-
-/**
- * Benchmarks for hashing functions. This class benchmarks various hasing functions for a range of
- * sizes of byte array. The input data is generated by a call to {@link Random#nextBytes}.
- *
- * <p>Parameters for the benchmark are:
- * <ul>
- * <li>size: The length of the byte array to hash.
- * <li>function: The name of the function(s) to test (eg, "goodFastHash32" or "murmur3_32")
- * </ul>
- *
- * @author David Beaumont
- */
-public class HashBenchmark extends SimpleBenchmark {
-
- @Param({"10", "1000", "1000000"})
- private int size;
-
- @Param private HashType function;
-
- private enum HashType {
- goodFastHash32() {
- @Override public long hash(byte[] data) {
- return Hashing.goodFastHash(32).hashBytes(data).asInt();
- }
- },
- goodFastHash64() {
- @Override public long hash(byte[] data) {
- return Hashing.goodFastHash(64).hashBytes(data).asLong();
- }
- },
- murmur32() {
- @Override public long hash(byte[] data) {
- return Hashing.murmur3_32().hashBytes(data).asInt();
- }
- },
- murmur128() {
- @Override public long hash(byte[] data) {
- return Hashing.murmur3_128().hashBytes(data).asLong();
- }
- },
- md5() {
- @Override public long hash(byte[] data) {
- return Hashing.md5().hashBytes(data).asLong();
- }
- };
- public abstract long hash(byte[] data);
- }
-
- private byte[] testData;
-
- @Override
- protected void setUp() {
- testData = new byte[size];
- new Random().nextBytes(testData);
- }
-
- public int timeHashFunction(int reps) {
- long dummy = 0;
- for (int i = 0; i < reps; i++) {
- dummy ^= function.hash(testData);
- }
- return (int) dummy;
- }
-
- public static void main(String[] args) {
- Runner.main(HashBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/hash/HashFunctionBenchmark.java b/guava-tests/benchmark/com/google/common/hash/HashFunctionBenchmark.java
deleted file mode 100644
index 92a8cf3..0000000
--- a/guava-tests/benchmark/com/google/common/hash/HashFunctionBenchmark.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2012 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.hash;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.hash.HashFunction;
-import com.google.common.hash.Hashing;
-
-import java.util.Random;
-
-/**
- * Benchmarks for comparing the various {@link HashFunction functions} that we provide.
- *
- * <p>Parameters for the benchmark are:
- * <ul>
- * <li>size: The length of the byte array to hash.
- * </ul>
- *
- * @author Kurt Alfred Kluever
- */
-public class HashFunctionBenchmark extends SimpleBenchmark {
-
- // Use a constant seed for all of the benchmarks to ensure apples to apples comparisons.
- private static final int RANDOM_SEED = new Random().nextInt();
-
- @Param({"10", "1000", "100000", "1000000"})
- private int size;
-
- private byte[] testBytes;
-
- @Override public void setUp() {
- testBytes = new byte[size];
- new Random(RANDOM_SEED).nextBytes(testBytes);
- }
-
- public int timeMurmur32HashFunction(int reps) {
- return runHashFunction(reps, Hashing.murmur3_32());
- }
-
- public int timeMurmur128HashFunction(int reps) {
- return runHashFunction(reps, Hashing.murmur3_128());
- }
-
- public int timeMd5HashFunction(int reps) {
- return runHashFunction(reps, Hashing.md5());
- }
-
- public int timeSha1HashFunction(int reps) {
- return runHashFunction(reps, Hashing.sha1());
- }
-
- public int timeSha256HashFunction(int reps) {
- return runHashFunction(reps, Hashing.sha256());
- }
-
- public int timeSha512HashFunction(int reps) {
- return runHashFunction(reps, Hashing.sha512());
- }
-
- private int runHashFunction(int reps, HashFunction hashFunction) {
- int result = 37;
- for (int i = 0; i < reps; i++) {
- result ^= hashFunction.hashBytes(testBytes).asInt();
- }
- return result;
- }
-
- public static void main(String[] args) {
- Runner.main(HashFunctionBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/hash/MessageDigestAlgorithmBenchmark.java b/guava-tests/benchmark/com/google/common/hash/MessageDigestAlgorithmBenchmark.java
deleted file mode 100644
index bef6e63..0000000
--- a/guava-tests/benchmark/com/google/common/hash/MessageDigestAlgorithmBenchmark.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2012 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.hash;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.hash.HashFunction;
-import com.google.common.hash.Hashing;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import java.util.Random;
-
-/**
- * Benchmarks for comparing {@link MessageDigest}s and {@link HashFunction}s that wrap
- * {@link MessageDigest}s.
- *
- * <p>Parameters for the benchmark are:
- * <ul>
- * <li>size: The length of the byte array to hash.
- * <li>algorithm: the algorithm to hash with (e.g. MD5, SHA1, etc.).
- * <li>hashMethod: how to hash the data (using the Hashing API or the MessageDigest API).
- * </ul>
- *
- * @author Kurt Alfred Kluever
- */
-public class MessageDigestAlgorithmBenchmark extends SimpleBenchmark {
- @Param({"10", "1000", "100000", "1000000"}) int size;
- @Param Algorithm algorithm;
- @Param HashMethod hashMethod;
-
- private enum HashMethod {
- MESSAGE_DIGEST_API() {
- @Override public byte[] hash(Algorithm algorithm, byte[] input) {
- MessageDigest md = algorithm.getMessageDigest();
- md.update(input);
- return md.digest();
- }
- },
- HASH_FUNCTION_API() {
- @Override public byte[] hash(Algorithm algorithm, byte[] input) {
- return algorithm.getHashFunction().hashBytes(input).asBytes();
- }
- };
- public abstract byte[] hash(Algorithm algorithm, byte[] input);
- }
-
- private enum Algorithm {
- MD5("MD5", Hashing.md5()),
- SHA_1("SHA-1", Hashing.sha1()),
- SHA_256("SHA-256", Hashing.sha256()),
- SHA_512("SHA-512", Hashing.sha512());
-
- private final String algorithmName;
- private final HashFunction hashFn;
- Algorithm(String algorithmName, HashFunction hashFn) {
- this.algorithmName = algorithmName;
- this.hashFn = hashFn;
- }
- public MessageDigest getMessageDigest() {
- try {
- return MessageDigest.getInstance(algorithmName);
- } catch (NoSuchAlgorithmException e) {
- throw new AssertionError(e);
- }
- }
- public HashFunction getHashFunction() {
- return hashFn;
- }
- }
-
- // Use a constant seed for all of the benchmarks to ensure apples to apples comparisons.
- private static final int RANDOM_SEED = new Random().nextInt();
-
- private byte[] testBytes;
-
- @Override public void setUp() {
- testBytes = new byte[size];
- new Random(RANDOM_SEED).nextBytes(testBytes);
- }
-
- public byte timeHashing(int reps) {
- byte result = 0x01;
- HashMethod hashMethod = this.hashMethod;
- Algorithm algorithm = this.algorithm;
- for (int i = 0; i < reps; i++) {
- result ^= hashMethod.hash(algorithm, testBytes)[0];
- }
- return result;
- }
-
- public static void main(String[] args) {
- Runner.main(MessageDigestAlgorithmBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/hash/MessageDigestCreationBenchmark.java b/guava-tests/benchmark/com/google/common/hash/MessageDigestCreationBenchmark.java
deleted file mode 100644
index 1adfd1d..0000000
--- a/guava-tests/benchmark/com/google/common/hash/MessageDigestCreationBenchmark.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2012 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.hash;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-
-import java.security.MessageDigest;
-
-/**
- * Benchmarks for comparing instance creation of {@link MessageDigest}s.
- *
- * @author Kurt Alfred Kluever
- */
-public class MessageDigestCreationBenchmark extends SimpleBenchmark {
-
- @Param({"MD5", "SHA-1", "SHA-256", "SHA-512"})
- private String algorithm;
-
- private MessageDigest md;
-
- public void setUp() throws Exception {
- md = MessageDigest.getInstance(algorithm);
- }
-
- public int timeGetInstance(int reps) throws Exception {
- int retValue = 0;
- for (int i = 0; i < reps; i++) {
- retValue ^= MessageDigest.getInstance(algorithm).getDigestLength();
- }
- return retValue;
- }
-
- public int timeClone(int reps) throws Exception {
- int retValue = 0;
- for (int i = 0; i < reps; i++) {
- retValue ^= ((MessageDigest) md.clone()).getDigestLength();
- }
- return retValue;
- }
-
- public static void main(String[] args) {
- Runner.main(MessageDigestCreationBenchmark.class, args);
- }
-}