Skip to content

Commit

Permalink
8288667: Reduce runtime of java.text microbenchmarks
Browse files Browse the repository at this point in the history
Reviewed-by: jvernee
  • Loading branch information
cl4es committed Jun 20, 2022
1 parent 695d865 commit d917e18
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions test/micro/org/openjdk/bench/java/text/DefFormatterBench.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022, 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 @@ -31,9 +31,10 @@
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
Expand All @@ -43,32 +44,41 @@

@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
@Fork(1)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(3)
@State(Scope.Benchmark)
public class DefFormatterBench {

@Param({"1.23", "1.49", "1.80", "1.7", "0.0", "-1.49", "-1.50", "9999.9123", "1.494", "1.495", "1.03", "25.996", "-25.996"})
public double value;
public double[] values;

private DefNumerFormat dnf = new DefNumerFormat();
@Setup
public void setup() {
values = new double[] {
1.23, 1.49, 1.80, 1.7, 0.0, -1.49, -1.50, 9999.9123, 1.494, 1.495, 1.03, 25.996, -25.996
};
}

private DefNumberFormat dnf = new DefNumberFormat();

@Benchmark
@OperationsPerInvocation(13)
public void testDefNumberFormatter(final Blackhole blackhole) {
blackhole.consume(this.dnf.format(this.value));
for (double value : values) {
blackhole.consume(this.dnf.format(value));
}
}

public static void main(String... args) throws Exception {
Options opts = new OptionsBuilder().include(DefFormatterBench.class.getSimpleName()).shouldDoGC(true).build();
new Runner(opts).run();
}

private static class DefNumerFormat {
private static class DefNumberFormat {

private final NumberFormat n;

public DefNumerFormat() {
public DefNumberFormat() {
this.n = NumberFormat.getInstance(Locale.ENGLISH);
this.n.setMaximumFractionDigits(2);
this.n.setMinimumFractionDigits(2);
Expand Down

1 comment on commit d917e18

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.