From 62ef3d149c9c5a71276ea9d4e0e1c2e9006a30f4 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 5fe37f971697..b9f28a7a9061 100644 --- a/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java +++ b/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java @@ -113,6 +113,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) { @@ -121,6 +138,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 5fe37f971697..b9f28a7a9061 100644 --- a/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java +++ b/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java @@ -113,6 +113,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) { @@ -121,6 +138,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]; }