Skip to content

Commit 62ef3d1

Browse files
java-team-github-botGoogle Java Core Libraries
authored and
Google Java Core Libraries
committed
Add HighwayFingerprint64 to ChecksumBenchmark
PiperOrigin-RevId: 691560282
1 parent 2076b8e commit 62ef3d1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java

+18
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ byte fingerprintChecksum(int reps) throws Exception {
113113
return result;
114114
}
115115

116+
// HighwayFingerprint64
117+
118+
@Benchmark
119+
byte highwayFingerprint64HashFunction(int reps) {
120+
return runHashFunction(reps, Hashing.highwayFingerprint64());
121+
}
122+
123+
@Benchmark
124+
byte highwayFingerprint64Checksum(int reps) throws Exception {
125+
byte result = 0x01;
126+
for (int i = 0; i < reps; i++) {
127+
HashCode checksum = Hashing.highwayFingerprint64().hashBytes(testBytes, 0, testBytes.length);
128+
result = (byte) (result ^ checksum.asLong());
129+
}
130+
return result;
131+
}
132+
116133
// Helpers + main
117134

118135
private byte runHashFunction(int reps, HashFunction hashFunction) {
@@ -121,6 +138,7 @@ private byte runHashFunction(int reps, HashFunction hashFunction) {
121138
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
122139
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
123140
result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0];
141+
result ^= Hashing.highwayFingerprint64().hashInt(reps).asBytes()[0];
124142
for (int i = 0; i < reps; i++) {
125143
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
126144
}

guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java

+18
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ byte fingerprintChecksum(int reps) throws Exception {
113113
return result;
114114
}
115115

116+
// HighwayFingerprint64
117+
118+
@Benchmark
119+
byte highwayFingerprint64HashFunction(int reps) {
120+
return runHashFunction(reps, Hashing.highwayFingerprint64());
121+
}
122+
123+
@Benchmark
124+
byte highwayFingerprint64Checksum(int reps) throws Exception {
125+
byte result = 0x01;
126+
for (int i = 0; i < reps; i++) {
127+
HashCode checksum = Hashing.highwayFingerprint64().hashBytes(testBytes, 0, testBytes.length);
128+
result = (byte) (result ^ checksum.asLong());
129+
}
130+
return result;
131+
}
132+
116133
// Helpers + main
117134

118135
private byte runHashFunction(int reps, HashFunction hashFunction) {
@@ -121,6 +138,7 @@ private byte runHashFunction(int reps, HashFunction hashFunction) {
121138
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
122139
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
123140
result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0];
141+
result ^= Hashing.highwayFingerprint64().hashInt(reps).asBytes()[0];
124142
for (int i = 0; i < reps; i++) {
125143
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
126144
}

0 commit comments

Comments
 (0)