You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LookupFileStoreBenchmark.java 1.9KB

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