Last active
November 11, 2022 09:22
-
-
Save matrixcloud/10fae5dd2dffade3cb28bf31c6acc910 to your computer and use it in GitHub Desktop.
JMH Benchmark Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@BenchmarkMode(Mode.AverageTime) | |
@Warmup(iterations = 3, time = 1) | |
@Measurement(iterations = 5, time = 5) | |
@Threads(4) | |
@Fork(1) | |
@State(value = Scope.Benchmark) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
public class KK { | |
private final XmlMapper xmlMapper; | |
private final String content; | |
{ | |
xmlMapper = new Jackson2ObjectMapperBuilder().createXmlMapper(true).indentOutput(true).build(); | |
xmlMapper.enable(ToXmlGenerator.Feature.WRITE_XML_1_1); | |
xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE); | |
content = ResourceLoader.read(new ClassPathResource("cw/shipment_req.xml")); | |
} | |
public static void main(String[] args) throws RunnerException { | |
Options opt = new OptionsBuilder() | |
.include(KK.class.getSimpleName()) | |
.result("/Users/cwa166/Downloads/Benchmark.json") | |
.resultFormat(ResultFormatType.JSON).build(); | |
new Runner(opt).run(); | |
} | |
@Benchmark | |
public void testXmlMapper() throws JsonProcessingException { | |
ShipmentReq base = ShipmentReq.base(); | |
base.getShipmentRequest().getDataContext().getDataTargetCollection().get(0).setType("T1"); | |
base.getShipmentRequest().getDataContext().getDataTargetCollection().get(0).setKey("k1"); | |
base.getShipmentRequest().getDataContext().getCompany().setCode("BBC"); | |
base.getShipmentRequest().getDataContext().setServerID("server1"); | |
xmlMapper.writeValueAsString(base); | |
} | |
@Benchmark | |
public void testResourceLoader() { | |
ResourceLoader.interpolate(content, "T1", "K1", "BBC", "server1"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refs: https://www.cnblogs.com/54chensongxia/p/15485421.html