Skip to content

Commit 503c9eb

Browse files
java-team-github-botGoogle Java Core Libraries
authored andcommitted
Add Fingerprint2011 to ChecksumBenchmark
PiperOrigin-RevId: 686542171
1 parent 5338f7c commit 503c9eb

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,31 @@ byte adler32Checksum(int reps) throws Exception {
9494
return result;
9595
}
9696

97+
// Fingerprint2011
98+
99+
@Benchmark
100+
byte fingerprintHashFunction(int reps) {
101+
return runHashFunction(reps, Hashing.fingerprint2011());
102+
}
103+
104+
@Benchmark
105+
byte fingerprintChecksum(int reps) throws Exception {
106+
byte result = 0x01;
107+
for (int i = 0; i < reps; i++) {
108+
HashCode checksum = new Fingerprint2011().hashBytes(testBytes, 0, testBytes.length);
109+
result = (byte) (result ^ checksum.asLong());
110+
}
111+
return result;
112+
}
113+
97114
// Helpers + main
98115

99116
private byte runHashFunction(int reps, HashFunction hashFunction) {
100117
byte result = 0x01;
101118
// Trick the JVM to prevent it from using the hash function non-polymorphically
102119
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
103120
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
121+
result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0];
104122
for (int i = 0; i < reps; i++) {
105123
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
106124
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,31 @@ byte adler32Checksum(int reps) throws Exception {
9494
return result;
9595
}
9696

97+
// Fingerprint2011
98+
99+
@Benchmark
100+
byte fingerprintHashFunction(int reps) {
101+
return runHashFunction(reps, Hashing.fingerprint2011());
102+
}
103+
104+
@Benchmark
105+
byte fingerprintChecksum(int reps) throws Exception {
106+
byte result = 0x01;
107+
for (int i = 0; i < reps; i++) {
108+
HashCode checksum = new Fingerprint2011().hashBytes(testBytes, 0, testBytes.length);
109+
result = (byte) (result ^ checksum.asLong());
110+
}
111+
return result;
112+
}
113+
97114
// Helpers + main
98115

99116
private byte runHashFunction(int reps, HashFunction hashFunction) {
100117
byte result = 0x01;
101118
// Trick the JVM to prevent it from using the hash function non-polymorphically
102119
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
103120
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
121+
result ^= Hashing.fingerprint2011().hashInt(reps).asBytes()[0];
104122
for (int i = 0; i < reps; i++) {
105123
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
106124
}

0 commit comments

Comments
 (0)