Skip to content

Commit bcf2f39

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 9b0109c commit bcf2f39

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
@@ -111,6 +111,23 @@ byte fingerprintChecksum(int reps) throws Exception {
111111
return result;
112112
}
113113

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

116133
private byte runHashFunction(int reps, HashFunction hashFunction) {
@@ -119,6 +136,7 @@ private byte runHashFunction(int reps, HashFunction hashFunction) {
119136
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
120137
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
121138
result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0];
139+
result ^= Hashing.highwayFingerprint64().hashInt(reps).asBytes()[0];
122140
for (int i = 0; i < reps; i++) {
123141
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
124142
}

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

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

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

116133
private byte runHashFunction(int reps, HashFunction hashFunction) {
@@ -119,6 +136,7 @@ private byte runHashFunction(int reps, HashFunction hashFunction) {
119136
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
120137
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
121138
result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0];
139+
result ^= Hashing.highwayFingerprint64().hashInt(reps).asBytes()[0];
122140
for (int i = 0; i < reps; i++) {
123141
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
124142
}

0 commit comments

Comments
 (0)