1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.benchmarks;
11
12 import java.io.IOException;
13 import java.nio.file.FileStore;
14 import java.nio.file.Files;
15 import java.nio.file.Path;
16 import java.util.concurrent.TimeUnit;
17
18 import org.eclipse.jgit.util.FileUtils;
19 import org.openjdk.jmh.annotations.Benchmark;
20 import org.openjdk.jmh.annotations.BenchmarkMode;
21 import org.openjdk.jmh.annotations.Mode;
22 import org.openjdk.jmh.annotations.OutputTimeUnit;
23 import org.openjdk.jmh.annotations.Scope;
24 import org.openjdk.jmh.annotations.Setup;
25 import org.openjdk.jmh.annotations.State;
26 import org.openjdk.jmh.annotations.TearDown;
27 import org.openjdk.jmh.profile.StackProfiler;
28 import org.openjdk.jmh.runner.Runner;
29 import org.openjdk.jmh.runner.RunnerException;
30 import org.openjdk.jmh.runner.options.Options;
31 import org.openjdk.jmh.runner.options.OptionsBuilder;
32
33 @State(Scope.Thread)
34 public class LookupFileStoreBenchmark {
35
36 Path path;
37
38 @Setup
39 public void setupBenchmark() throws IOException {
40 path = Files.createTempFile("test", "x");
41 }
42
43 @TearDown
44 public void teardown() throws IOException {
45 FileUtils.delete(path.toFile(), FileUtils.RETRY);
46 }
47
48 @Benchmark
49 @BenchmarkMode({ Mode.AverageTime })
50 @OutputTimeUnit(TimeUnit.NANOSECONDS)
51 public FileStore testLookupFileStore() throws IOException {
52 FileStore fs = Files.getFileStore(path);
53 return fs;
54 }
55
56 public static void main(String[] args) throws RunnerException {
57 Options opt = new OptionsBuilder()
58 .include(LookupFileStoreBenchmark.class.getSimpleName())
59 .addProfiler(StackProfiler.class)
60
61 .forks(1).jvmArgs("-ea").build();
62 new Runner(opt).run();
63 }
64 }