Skip to content

Commit

Permalink
Complete micro-benchmark on hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Feb 10, 2015
1 parent af718e7 commit 65b0ec4
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ public class HashBenchmark {
@Param({"1", "100", "1000", "10000", "100000", "1000000"})
public int size;

XXHash32 xxHash32 = XXHashFactory.fastestInstance().hash32();
XXHash64 xxHash64 = XXHashFactory.fastestInstance().hash64();
XXHash32 xxHash32Jni = XXHashFactory.fastestInstance().hash32();
XXHash64 xxHash64Jni = XXHashFactory.fastestInstance().hash64();
XXHash32 xxHash32Unsafe = XXHashFactory.fastestJavaInstance().hash32();
XXHash64 xxHash64Unsafe = XXHashFactory.fastestJavaInstance().hash64();
XXHash32 xxHash32 = XXHashFactory.safeInstance().hash32();
XXHash64 xxHash64 = XXHashFactory.safeInstance().hash64();

byte[] bytes;

Expand All @@ -85,13 +89,41 @@ public int xxhash32() throws Exception {
return xxHash32.hash(bytes, 0, bytes.length, seed);
}

@Benchmark
public int xxhash32Jni() throws Exception {
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
return xxHash32Jni.hash(bytes, 0, bytes.length, seed);
}

@Benchmark
public int xxhash32Unsafe() throws Exception {
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
return xxHash32Unsafe.hash(bytes, 0, bytes.length, seed);
}

@Benchmark
public long xxhash64() throws Exception {
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
return xxHash64.hash(bytes, 0, bytes.length, seed);
}

@Benchmark
public long xxhash64Jni() throws Exception {
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
return xxHash64Jni.hash(bytes, 0, bytes.length, seed);
}

@Benchmark
public long xxhash64Unsafe() throws Exception {
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
return xxHash64Unsafe.hash(bytes, 0, bytes.length, seed);
}

/**
* You can this benchmark with maven command-line (see run.sh) or by executing this method
* in IDE
Expand Down

0 comments on commit 65b0ec4

Please sign in to comment.