System.out.println("method call");
> # Run progress: 0,00% complete, ETA 00:00:11
> # Fork: 1 of 1
> # Warmup Iteration 1: method call
> method call
> <failure>
objectMapper.readValue(..)
@Param( { "1.xml", "10.xml", "100.xml" } )
String file;
private String jsonData;
@Setup
public void setup() {
jsonData = getContent(file);
}
@Benchmark
public void jacksonDeserializeStreamTest(Blackhole bh) throws IOException {
bh.consume(objectMapper.readValue(jsonData, Cat.class));
}
private static String getContent(String fileName) {
try {
InputStream stream = PersonGenerator.class.getClassLoader().getResourceAsStream(fileName);
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = stream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString("UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Gson-vs-Jackson-Benchmark
Java I/O - Reuse InputStream Object
String rawData = getContent("cats.json");
StringReader reader = new StringReader(rawData);
[...]
reader.mark(0); // reset
m.readValue(reader, type);
[...]