Skip to content

Commit

Permalink
Add HighwayFingerprint64 to ChecksumBenchmark
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 691560282
  • Loading branch information
java-team-github-bot authored and Google Java Core Libraries committed Nov 4, 2024
1 parent 9b0109c commit bcf2f39
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
}
Expand Down

0 comments on commit bcf2f39

Please sign in to comment.