diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-02-10 23:03:46 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-02-10 23:03:46 +0100 |
commit | 65b0ec4e41f05e9ebf7796d4688cf778f7a14dd9 (patch) | |
tree | 0d024d47ccad6ad3d372d470ab5503d0684aba98 /microbenchmark-template | |
parent | af718e7ca90cc78eac1da85c970c63b55f6cd50e (diff) | |
download | sonarqube-65b0ec4e41f05e9ebf7796d4688cf778f7a14dd9.tar.gz sonarqube-65b0ec4e41f05e9ebf7796d4688cf778f7a14dd9.zip |
Complete micro-benchmark on hashes
Diffstat (limited to 'microbenchmark-template')
-rw-r--r-- | microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java index a02f30fdd38..11bc14293b9 100644 --- a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java +++ b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java @@ -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; @@ -86,12 +90,40 @@ public class HashBenchmark { } @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 |