File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
android/guava-tests/benchmark/com/google/common/hash
guava-tests/benchmark/com/google/common/hash Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments