@@ -0,0 +1,2286 @@
+/*%0A * Copyright 2019 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.gradle;%0A%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.Fork;%0Aimport org.openjdk.jmh.annotations.Measurement;%0Aimport org.openjdk.jmh.annotations.Scope;%0Aimport org.openjdk.jmh.annotations.State;%0Aimport org.openjdk.jmh.annotations.Warmup;%0Aimport org.openjdk.jmh.infra.Blackhole;%0A%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport java.util.Optional;%0A%0Aimport static java.util.concurrent.TimeUnit.SECONDS;%0A%0A/*%0A * Benchmark                     Mode  Cnt          Score         Error  Units%0A * OptionalBenchmark.nullCheck  thrpt   20  107887111.061 %C2%B1  882182.482  ops/s%0A * OptionalBenchmark.optional   thrpt   20   86746312.090 %C2%B1 1150860.296  ops/s%0A **/%0A@Fork(2)%0A@Warmup(iterations = 10, time = 1, timeUnit = SECONDS)%0A@Measurement(iterations = 10, time = 1, timeUnit = SECONDS)%0A@State(Scope.Benchmark)%0Apublic class OptionalBenchmark %7B%0A%0A    final Path path = Paths.get(%22.%22);%0A    final Path pathRoot = Paths.get(%22.%22).toAbsolutePath().getRoot();%0A%0A    @Benchmark%0A    public void nullCheck(Blackhole bh) %7B%0A        bh.consume(nullCheck(path));%0A        bh.consume(nullCheck(pathRoot));%0A    %7D%0A%0A    private static Object nullCheck(Path path) %7B%0A        Path fileName = path.getFileName();%0A        if (fileName != null) %7B%0A            return fileName.toString();%0A        %7D else %7B%0A            return %22%22;%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    public void optional(Blackhole bh) %7B%0A        bh.consume(optional(path));%0A        bh.consume(optional(pathRoot));%0A    %7D%0A%0A    private static Object optional(Path path) %7B%0A        return Optional.ofNullable(path.getFileName())%0A            .map(Object::toString)%0A            .orElse(%22%22);%0A    %7D%0A%7D%0A

Add micro-benchmark to clarify Optional usage viability