Skip to content

Commit

Permalink
Fold ToPath into FileOpen, add root benchmarks to keep mix comparable
Browse files Browse the repository at this point in the history
  • Loading branch information
cl4es committed Jan 19, 2021
1 parent 27a55ee commit 18c3105
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 78 deletions.
62 changes: 56 additions & 6 deletions test/micro/org/openjdk/bench/java/io/FileOpen.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,23 +28,24 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;

/**
* Tests the overheads of I/O API.
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
@Warmup(time=2, iterations=5)
@Measurement(time=3, iterations=5)
@Fork(value=2, jvmArgs="-Xmx1g")
public class FileOpen {

public String normalFile = "/test/dir/file/name.txt";
public String root = "/";
public String trailingSlash = "/test/dir/file/name.txt/";
public String notNormalizedFile = "/test/dir/file//name.txt";
private String normalFile = "/test/dir/file/name.txt";
private String root = "/";
private String trailingSlash = "/test/dir/file/name.txt/";
private String notNormalizedFile = "/test/dir/file//name.txt";

public File tmp;

Expand All @@ -68,6 +69,11 @@ public File normalized() {
return new File(normalFile);
}

@Benchmark
public File root() {
return new File(root);
}

@Benchmark
public File trailingSlash() {
return new File(trailingSlash);
Expand All @@ -85,4 +91,48 @@ public boolean booleanAttributes() {
&& tmp.isDirectory()
&& tmp.isFile();
}

/**
* Examine overheads of converting Files to Paths
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
@Warmup(time=2, iterations=5)
@Measurement(time=3, iterations=5)
@Fork(value=2, jvmArgs="-Xmx1g")
public static class ToPath {
private String normalFile = "/test/dir/file/name.txt";
private String root = "/";
private String trailingSlash = "/test/dir/file/name.txt/";
private String notNormalizedFile = "/test/dir/file//name.txt";

@Benchmark
public void mix(Blackhole bh) {
bh.consume(new File(normalFile).toPath());
bh.consume(new File(root).toPath());
bh.consume(new File(trailingSlash).toPath());
bh.consume(new File(notNormalizedFile).toPath());
}

@Benchmark
public Path normalized() {
return new File(normalFile).toPath();
}

@Benchmark
public File root() {
return new File(root);
}

@Benchmark
public Path trailingSlash() {
return new File(trailingSlash).toPath();
}

@Benchmark
public Path notNormalized() {
return new File(notNormalizedFile).toPath();
}
}
}
72 changes: 0 additions & 72 deletions test/micro/org/openjdk/bench/java/io/FileToPath.java

This file was deleted.

0 comments on commit 18c3105

Please sign in to comment.