From bcf2f393e1957a6db57b3532ecc8476ac5b1ff90 Mon Sep 17 00:00:00 2001 From: Google Java Core Libraries Date: Wed, 30 Oct 2024 14:44:33 -0700 Subject: [PATCH] Add HighwayFingerprint64 to ChecksumBenchmark PiperOrigin-RevId: 691560282 --- .../google/common/hash/ChecksumBenchmark.java | 18 ++++++++++++++++++ .../google/common/hash/ChecksumBenchmark.java | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) 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 868a9d390f28..c4661d7b2689 100644 --- a/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java +++ b/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java @@ -111,6 +111,23 @@ byte fingerprintChecksum(int reps) throws Exception { return result; } + // HighwayFingerprint64 + + @Benchmark + byte highwayFingerprint64HashFunction(int reps) { + return runHashFunction(reps, Hashing.highwayFingerprint64()); + } + + @Benchmark + byte highwayFingerprint64Checksum(int reps) throws Exception { + byte result = 0x01; + for (int i = 0; i < reps; i++) { + HashCode checksum = Hashing.highwayFingerprint64().hashBytes(testBytes, 0, testBytes.length); + result = (byte) (result ^ checksum.asLong()); + } + return result; + } + // Helpers + main private byte runHashFunction(int reps, HashFunction hashFunction) { @@ -119,6 +136,7 @@ private byte runHashFunction(int reps, HashFunction hashFunction) { result ^= Hashing.crc32().hashInt(reps).asBytes()[0]; result ^= Hashing.adler32().hashInt(reps).asBytes()[0]; result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0]; + result ^= Hashing.highwayFingerprint64().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 868a9d390f28..c4661d7b2689 100644 --- a/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java +++ b/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java @@ -111,6 +111,23 @@ byte fingerprintChecksum(int reps) throws Exception { return result; } + // HighwayFingerprint64 + + @Benchmark + byte highwayFingerprint64HashFunction(int reps) { + return runHashFunction(reps, Hashing.highwayFingerprint64()); + } + + @Benchmark + byte highwayFingerprint64Checksum(int reps) throws Exception { + byte result = 0x01; + for (int i = 0; i < reps; i++) { + HashCode checksum = Hashing.highwayFingerprint64().hashBytes(testBytes, 0, testBytes.length); + result = (byte) (result ^ checksum.asLong()); + } + return result; + } + // Helpers + main private byte runHashFunction(int reps, HashFunction hashFunction) { @@ -119,6 +136,7 @@ private byte runHashFunction(int reps, HashFunction hashFunction) { result ^= Hashing.crc32().hashInt(reps).asBytes()[0]; result ^= Hashing.adler32().hashInt(reps).asBytes()[0]; result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0]; + result ^= Hashing.highwayFingerprint64().hashInt(reps).asBytes()[0]; for (int i = 0; i < reps; i++) { result ^= hashFunction.hashBytes(testBytes).asBytes()[0]; }