package io.gatling.jsonbenchmark.bytes; import static io.gatling.jsonbenchmark.bytes.Buffers.*; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.GenerateMicroBenchmark; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.logic.BlackHole; import com.google.gson.Gson; public class GSONBenchmark { private static final Gson GSON = new Gson(); private Object parse(byte[] bytes) throws Exception { Reader reader = new InputStreamReader(new ByteArrayInputStream(bytes), StandardCharsets.UTF_8); return GSON.fromJson(reader, Map.class); } @GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void actionLabel(BlackHole bh) throws Exception { bh.consume(parse(ACTION_LABEL_BYTES)); } @GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void citmCatalog(BlackHole bh) throws Exception { bh.consume(parse(CITM_CATALOG_BYTES)); } @GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void medium(BlackHole bh) throws Exception { bh.consume(parse(MEDIUM_BYTES)); } @GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void menu(BlackHole bh) throws Exception { bh.consume(parse(MENU_BYTES)); } @GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void sgml(BlackHole bh) throws Exception { bh.consume(parse(SGML_BYTES)); } @GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void small(BlackHole bh) throws Exception { bh.consume(parse(SMALL_BYTES)); } @GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void webxml(BlackHole bh) throws Exception { bh.consume(parse(WEBXML_BYTES)); } @GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void widget(BlackHole bh) throws Exception { bh.consume(parse(WIDGET_BYTES)); } }