Debian Codegraph @

src/test/java/io/airlift/slice/BenchmarkXxHash64.java

raw
1 /*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14 package io.airlift.slice;
15
16 import org.openjdk.jmh.annotations.Fork;
17 import org.openjdk.jmh.annotations.Benchmark;
18 import org.openjdk.jmh.annotations.Measurement;
19 import org.openjdk.jmh.annotations.OutputTimeUnit;
20 import org.openjdk.jmh.annotations.Scope;
21 import org.openjdk.jmh.annotations.State;
22 import org.openjdk.jmh.annotations.Warmup;
23 import org.openjdk.jmh.runner.Runner;
24 import org.openjdk.jmh.runner.RunnerException;
25 import org.openjdk.jmh.runner.options.Options;
26 import org.openjdk.jmh.runner.options.OptionsBuilder;
27 import org.openjdk.jmh.runner.options.VerboseMode;
28
29 import java.util.concurrent.TimeUnit;
30
31 @State(Scope.Thread)
32 @OutputTimeUnit(TimeUnit.SECONDS)
33 @Fork(5)
34 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
35 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
36 public class BenchmarkXxHash64
37 {
38 @Benchmark
39 public long xxhash64(BenchmarkData data, ByteCounter counter)
40 {
41 counter.add(data.getSlice().length());
42 return XxHash64.hash(data.getSlice());
43 }
44
45 @Benchmark
46 public long specializedHashLong(SingleLong data, ByteCounter counter)
47 {
48 counter.add(SizeOf.SIZE_OF_LONG);
49 return XxHash64.hash(data.getValue());
50 }
51
52 public static void main(String[] args)
53 throws RunnerException
54 {
55 Options options = new OptionsBuilder()
56 .verbosity(VerboseMode.NORMAL)
57 .include(".*" + BenchmarkXxHash64.class.getSimpleName() + ".*")
58 .build();
59
60 new Runner(options).run();
61 }
62 }