diff --git a/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java b/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java index 925db1a027eb..868a9d390f28 100644 --- a/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java +++ b/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java @@ -94,6 +94,23 @@ byte adler32Checksum(int reps) throws Exception { return result; } + // Fingerprint2011 + + @Benchmark + byte fingerprintHashFunction(int reps) { + return runHashFunction(reps, Hashing.fingerprint2011()); + } + + @Benchmark + byte fingerprintChecksum(int reps) throws Exception { + byte result = 0x01; + for (int i = 0; i < reps; i++) { + HashCode checksum = new Fingerprint2011().hashBytes(testBytes, 0, testBytes.length); + result = (byte) (result ^ checksum.asLong()); + } + return result; + } + // Helpers + main private byte runHashFunction(int reps, HashFunction hashFunction) { @@ -101,6 +118,7 @@ private byte runHashFunction(int reps, HashFunction hashFunction) { // 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]; + result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0]; for (int i = 0; i < reps; i++) { result ^= hashFunction.hashBytes(testBytes).asBytes()[0]; } diff --git a/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java b/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java index 925db1a027eb..868a9d390f28 100644 --- a/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java +++ b/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java @@ -94,6 +94,23 @@ byte adler32Checksum(int reps) throws Exception { return result; } + // Fingerprint2011 + + @Benchmark + byte fingerprintHashFunction(int reps) { + return runHashFunction(reps, Hashing.fingerprint2011()); + } + + @Benchmark + byte fingerprintChecksum(int reps) throws Exception { + byte result = 0x01; + for (int i = 0; i < reps; i++) { + HashCode checksum = new Fingerprint2011().hashBytes(testBytes, 0, testBytes.length); + result = (byte) (result ^ checksum.asLong()); + } + return result; + } + // Helpers + main private byte runHashFunction(int reps, HashFunction hashFunction) { @@ -101,6 +118,7 @@ private byte runHashFunction(int reps, HashFunction hashFunction) { // 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]; + result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0]; for (int i = 0; i < reps; i++) { result ^= hashFunction.hashBytes(testBytes).asBytes()[0]; }