Skip to content

Instantly share code, notes, and snippets.

@sadiqj
Created April 13, 2020 15:23
Show Gist options
  • Select an option

  • Save sadiqj/1e4d299adbad36bf51bbe41859dfb1b5 to your computer and use it in GitHub Desktop.

Select an option

Save sadiqj/1e4d299adbad36bf51bbe41859dfb1b5 to your computer and use it in GitHub Desktop.
package com.opsian;
import org.openjdk.jmh.Main;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jol.info.ClassLayout;
import com.opsian.*;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@State(Scope.Benchmark)
public class TlabTest {
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:-UseTLAB"})
@Threads(1)
public Object allocateWithoutTLABOneThreadObj() {
return new Object();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:+UseTLAB"})
@Threads(1)
public Object allocateWithTLABOneThreadsObj() {
return new Object();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:-UseTLAB"})
@Threads(4)
public Object allocateWithoutTLABFourThreadsObj() {
return new Object();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:+UseTLAB"})
@Threads(4)
public Object allocateWithTLABFourThreadsObj() {
return new Object();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:-UseTLAB"})
@Threads(1)
public Object allocateWithoutTLABOneThreadSmall() {
return new SmallObj();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:+UseTLAB"})
@Threads(1)
public Object allocateWithTLABOneThreadsSmall() {
return new SmallObj();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:-UseTLAB"})
@Threads(4)
public Object allocateWithoutTLABFourThreadsSmall() {
return new SmallObj();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:+UseTLAB"})
@Threads(4)
public Object allocateWithTLABFourThreadsSmall() {
return new SmallObj();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:-UseTLAB"})
@Threads(1)
public Object allocateWithoutTLABOneThreadLarge() {
return new LargeObj();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:+UseTLAB"})
@Threads(1)
public Object allocateWithTLABOneThreadsLarge() {
return new LargeObj();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:-UseTLAB"})
@Threads(4)
public Object allocateWithoutTLABFourThreadsLarge() {
return new LargeObj();
}
@Benchmark
@Fork(jvmArgsAppend = {"-XX:+UseParallelGC","-XX:+UseTLAB"})
@Threads(4)
public Object allocateWithTLABFourThreadsLarge() {
return new LargeObj();
}
public static void main(String[] args) throws Exception {
Main.main(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment