Skip to content
Permalink
Browse files

Make java6/9 benchmarks not use constants

While it makes the results faster, it's not realistic.   gen and taskname can be constants, but tags and times are not.

```
Benchmark                                                  Mode  Cnt   Score   Error  Units
VarHandleGeneratorBenchmark.getAndSetAndGetGeneration      avgt    5   2.685 ± 0.018  ns/op
VarHandleGeneratorBenchmark.getGeneration                  avgt    5   2.338 ± 0.013  ns/op
VarHandleGeneratorBenchmark.racyGetAndSetAndGetGeneration  avgt    5  19.649 ± 3.114  ns/op
VarHandleMarkHolderBenchmark.event_name_noTag              avgt    5   3.592 ± 0.444  ns/op
VarHandleMarkHolderBenchmark.event_name_subname            avgt    5   5.306 ± 0.532  ns/op
VarHandleMarkHolderBenchmark.event_name_tag                avgt    5   5.663 ± 0.074  ns/op
VarHandleMarkHolderBenchmark.link                          avgt    5   2.543 ± 0.087  ns/op
VarHandleMarkHolderBenchmark.start_name_noTag              avgt    5   3.674 ± 0.058  ns/op
VarHandleMarkHolderBenchmark.start_name_subname            avgt    5   4.937 ± 0.094  ns/op
VarHandleMarkHolderBenchmark.start_name_tag                avgt    5   5.608 ± 0.130  ns/op
VarHandleMarkHolderBenchmark.stop_name_noTag               avgt    5   3.496 ± 0.148  ns/op
VarHandleMarkHolderBenchmark.stop_name_subname             avgt    5   5.134 ± 0.074  ns/op
VarHandleMarkHolderBenchmark.stop_name_tag                 avgt    5   5.895 ± 0.047  ns/op

Benchmark                                                 Mode  Cnt   Score   Error  Units
SynchronizedMarkHolderBenchmark.event_name_noTag          avgt    5   6.409 ± 0.141  ns/op
SynchronizedMarkHolderBenchmark.event_name_subname        avgt    5   6.755 ± 0.066  ns/op
SynchronizedMarkHolderBenchmark.event_name_tag            avgt    5   9.081 ± 0.149  ns/op
SynchronizedMarkHolderBenchmark.link                      avgt    5   3.344 ± 0.019  ns/op
SynchronizedMarkHolderBenchmark.start_name_noTag          avgt    5   6.538 ± 0.023  ns/op
SynchronizedMarkHolderBenchmark.start_name_subname        avgt    5   6.763 ± 0.067  ns/op
SynchronizedMarkHolderBenchmark.start_name_tag            avgt    5   9.552 ± 0.095  ns/op
SynchronizedMarkHolderBenchmark.stop_name_noTag           avgt    5   6.474 ± 0.059  ns/op
SynchronizedMarkHolderBenchmark.stop_name_subname         avgt    5   7.919 ± 0.049  ns/op
SynchronizedMarkHolderBenchmark.stop_name_tag             avgt    5   9.768 ± 0.728  ns/op
VolatileGeneratorBenchmark.getAndSetAndGetGeneration      avgt    5   7.667 ± 0.052  ns/op
VolatileGeneratorBenchmark.getGeneration                  avgt    5   2.265 ± 0.007  ns/op
VolatileGeneratorBenchmark.ifEnabled                      avgt    5   0.669 ± 0.010  ns/op
VolatileGeneratorBenchmark.racyGetAndSetAndGetGeneration  avgt    5  87.784 ± 1.516  ns/op
```
  • Loading branch information
carl-mastrangelo committed Nov 12, 2019
1 parent f95b2e2 commit 0ffd823da29e5363e8886d8d6b66d35c020591cd
@@ -16,6 +16,7 @@

package io.perfmark.java6;

import io.perfmark.impl.Generator;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
@@ -24,78 +25,86 @@
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

@State(Scope.Benchmark)
@State(Scope.Thread)
public class SynchronizedMarkHolderBenchmark {

private static final long gen = 1 << Generator.GEN_OFFSET;
private static final String taskName = "hi";

public final SynchronizedMarkHolder markHolder = new SynchronizedMarkHolder(16384);

private String tagName = "tag";
private long tagId = 0xf0f0;
private long nanoTime = 0xf1f1;
private long linkId = 0xf2f2;

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void start_name_tag() {
markHolder.start(1, "hi", "tag", 2, 1234);
markHolder.start(gen, taskName, tagName, tagId, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void start_name_noTag() {
markHolder.start(1, "hi", 1234);
markHolder.start(gen, taskName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void start_name_subname() {
markHolder.start(1, "hi", "there", 1234);
markHolder.start(gen, taskName, taskName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void stop_name_tag() {
markHolder.stop(1, "hi", "tag", 2, 1234);
markHolder.stop(gen, taskName, tagName, tagId, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void stop_name_noTag() {
markHolder.stop(1, "hi", 1234);
markHolder.stop(gen, taskName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void stop_name_subname() {
markHolder.stop(1, "hi", "there", 1234);
markHolder.stop(gen, taskName, tagName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void link() {
markHolder.link(1, 9999);
markHolder.link(gen, linkId);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void event_name_tag() {
markHolder.event(1, "hi", "tag", 2, 8);
markHolder.event(gen, taskName, tagName, tagId, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void event_name_noTag() {
markHolder.event(1, "hi", 2);
markHolder.event(gen, taskName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void event_name_subname() {
markHolder.event(1, "hi", "there", 2);
markHolder.event(gen, taskName, taskName, nanoTime);
}
}
@@ -16,6 +16,7 @@

package io.perfmark.java9;

import io.perfmark.impl.Generator;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
@@ -24,78 +25,86 @@
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

@State(Scope.Benchmark)
@State(Scope.Thread)
public class VarHandleMarkHolderBenchmark {

private static final long gen = 1 << Generator.GEN_OFFSET;
private static final String taskName = "hi";

public final VarHandleMarkHolder markHolder = new VarHandleMarkHolder(16384);

private String tagName = "tag";
private long tagId = 0xf0f0;
private long nanoTime = 0xf1f1;
private long linkId = 0xf2f2;

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void start_name_tag() {
markHolder.start(1, "hi", "tag", 2, 1234);
markHolder.start(gen, taskName, tagName, tagId, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void start_name_noTag() {
markHolder.start(1, "hi", 1234);
markHolder.start(gen, taskName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void start_name_subname() {
markHolder.start(1, "hi", "there", 1234);
markHolder.start(gen, taskName, taskName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void stop_name_tag() {
markHolder.stop(1, "hi", "tag", 2, 1234);
markHolder.stop(gen, taskName, tagName, tagId, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void stop_name_noTag() {
markHolder.stop(1, "hi", 1234);
markHolder.stop(gen, taskName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void stop_name_subname() {
markHolder.stop(1, "hi", "there", 1234);
markHolder.stop(gen, taskName, tagName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void link() {
markHolder.link(1, 9999);
markHolder.link(gen, linkId);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void event_name_tag() {
markHolder.event(1, "hi", "tag", 2, 8);
markHolder.event(gen, taskName, tagName, tagId, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void event_name_noTag() {
markHolder.event(1, "hi", 8);
markHolder.event(gen, taskName, nanoTime);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void event_name_subname() {
markHolder.event(1, "hi", "there", 2);
markHolder.event(gen, taskName, taskName, nanoTime);
}
}

0 comments on commit 0ffd823

Please sign in to comment.
You can’t perform that action at this time.