xref: /JGit/org.eclipse.jgit.benchmarks/src/org/eclipse/jgit/benchmarks/LookupFileStoreBenchmark.java (revision 5c5f7c6b146b24f2bd4afae1902df85ad6e57ea3)
125a611ccSMatthias Sohn /*
2*5c5f7c6bSMatthias Sohn  * Copyright (C) 2019, Matthias Sohn <matthias.sohn@sap.com> and others
325a611ccSMatthias Sohn  *
4*5c5f7c6bSMatthias Sohn  * This program and the accompanying materials are made available under the
5*5c5f7c6bSMatthias Sohn  * terms of the Eclipse Distribution License v. 1.0 which is available at
6*5c5f7c6bSMatthias Sohn  * https://www.eclipse.org/org/documents/edl-v10.php.
725a611ccSMatthias Sohn  *
8*5c5f7c6bSMatthias Sohn  * SPDX-License-Identifier: BSD-3-Clause
925a611ccSMatthias Sohn  */
1025a611ccSMatthias Sohn package org.eclipse.jgit.benchmarks;
1125a611ccSMatthias Sohn 
1225a611ccSMatthias Sohn import java.io.IOException;
1325a611ccSMatthias Sohn import java.nio.file.FileStore;
1425a611ccSMatthias Sohn import java.nio.file.Files;
1525a611ccSMatthias Sohn import java.nio.file.Path;
1625a611ccSMatthias Sohn import java.util.concurrent.TimeUnit;
1725a611ccSMatthias Sohn 
1825a611ccSMatthias Sohn import org.eclipse.jgit.util.FileUtils;
1925a611ccSMatthias Sohn import org.openjdk.jmh.annotations.Benchmark;
2025a611ccSMatthias Sohn import org.openjdk.jmh.annotations.BenchmarkMode;
2125a611ccSMatthias Sohn import org.openjdk.jmh.annotations.Mode;
2225a611ccSMatthias Sohn import org.openjdk.jmh.annotations.OutputTimeUnit;
2325a611ccSMatthias Sohn import org.openjdk.jmh.annotations.Scope;
2425a611ccSMatthias Sohn import org.openjdk.jmh.annotations.Setup;
2525a611ccSMatthias Sohn import org.openjdk.jmh.annotations.State;
2625a611ccSMatthias Sohn import org.openjdk.jmh.annotations.TearDown;
2725a611ccSMatthias Sohn import org.openjdk.jmh.profile.StackProfiler;
2825a611ccSMatthias Sohn import org.openjdk.jmh.runner.Runner;
2925a611ccSMatthias Sohn import org.openjdk.jmh.runner.RunnerException;
3025a611ccSMatthias Sohn import org.openjdk.jmh.runner.options.Options;
3125a611ccSMatthias Sohn import org.openjdk.jmh.runner.options.OptionsBuilder;
3225a611ccSMatthias Sohn 
3325a611ccSMatthias Sohn @State(Scope.Thread)
3425a611ccSMatthias Sohn public class LookupFileStoreBenchmark {
3525a611ccSMatthias Sohn 
3625a611ccSMatthias Sohn 	Path path;
3725a611ccSMatthias Sohn 
3825a611ccSMatthias Sohn 	@Setup
setupBenchmark()3925a611ccSMatthias Sohn 	public void setupBenchmark() throws IOException {
4025a611ccSMatthias Sohn 		path = Files.createTempFile("test", "x");
4125a611ccSMatthias Sohn 	}
4225a611ccSMatthias Sohn 
4325a611ccSMatthias Sohn 	@TearDown
teardown()4425a611ccSMatthias Sohn 	public void teardown() throws IOException {
4525a611ccSMatthias Sohn 		FileUtils.delete(path.toFile(), FileUtils.RETRY);
4625a611ccSMatthias Sohn 	}
4725a611ccSMatthias Sohn 
4825a611ccSMatthias Sohn 	@Benchmark
4925a611ccSMatthias Sohn 	@BenchmarkMode({ Mode.AverageTime })
5025a611ccSMatthias Sohn 	@OutputTimeUnit(TimeUnit.NANOSECONDS)
testLookupFileStore()5125a611ccSMatthias Sohn 	public FileStore testLookupFileStore() throws IOException {
5225a611ccSMatthias Sohn 		FileStore fs = Files.getFileStore(path);
5325a611ccSMatthias Sohn 		return fs;
5425a611ccSMatthias Sohn 	}
5525a611ccSMatthias Sohn 
main(String[] args)5625a611ccSMatthias Sohn 	public static void main(String[] args) throws RunnerException {
5725a611ccSMatthias Sohn 		Options opt = new OptionsBuilder()
5825a611ccSMatthias Sohn 				.include(LookupFileStoreBenchmark.class.getSimpleName())
5925a611ccSMatthias Sohn 				.addProfiler(StackProfiler.class)
6025a611ccSMatthias Sohn 				// .addProfiler(GCProfiler.class)
6125a611ccSMatthias Sohn 				.forks(1).jvmArgs("-ea").build();
6225a611ccSMatthias Sohn 		new Runner(opt).run();
6325a611ccSMatthias Sohn 	}
6425a611ccSMatthias Sohn }
65