xref: /JGit/org.eclipse.jgit.benchmarks/src/org/eclipse/jgit/benchmarks/LookupFileStoreBenchmark.java (revision 5c5f7c6b146b24f2bd4afae1902df85ad6e57ea3)
1 /*
2  * Copyright (C) 2019, Matthias Sohn <matthias.sohn@sap.com> and others
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Distribution License v. 1.0 which is available at
6  * https://www.eclipse.org/org/documents/edl-v10.php.
7  *
8  * SPDX-License-Identifier: BSD-3-Clause
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
setupBenchmark()39 	public void setupBenchmark() throws IOException {
40 		path = Files.createTempFile("test", "x");
41 	}
42 
43 	@TearDown
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)
testLookupFileStore()51 	public FileStore testLookupFileStore() throws IOException {
52 		FileStore fs = Files.getFileStore(path);
53 		return fs;
54 	}
55 
main(String[] args)56 	public static void main(String[] args) throws RunnerException {
57 		Options opt = new OptionsBuilder()
58 				.include(LookupFileStoreBenchmark.class.getSimpleName())
59 				.addProfiler(StackProfiler.class)
60 				// .addProfiler(GCProfiler.class)
61 				.forks(1).jvmArgs("-ea").build();
62 		new Runner(opt).run();
63 	}
64 }
65