Feature/bael 4911 tiered compilation (#10958)
* BASE-4911: Tiered Compilation Initial Commit * BASE-4911: Use Generics
This commit is contained in:
parent
fe8ec4460c
commit
4f3f287923
|
@ -21,6 +21,16 @@
|
|||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.tieredcompilation;
|
||||
|
||||
public class Article {
|
||||
|
||||
private String name;
|
||||
private String author;
|
||||
|
||||
public Article(String name, String author) {
|
||||
this.name = name;
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.tieredcompilation;
|
||||
|
||||
public interface Formatter {
|
||||
|
||||
<T> String format(T object) throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.tieredcompilation;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
|
||||
public class JsonFormatter implements Formatter {
|
||||
|
||||
private static final JsonMapper mapper = new JsonMapper();
|
||||
|
||||
@Override
|
||||
public <T> String format(T object) throws JsonProcessingException {
|
||||
return mapper.writeValueAsString(object);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.tieredcompilation;
|
||||
|
||||
public class TieredCompilation {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (int i = 0; i < 1_000_000; i++) {
|
||||
Formatter formatter;
|
||||
if (i < 500_000) {
|
||||
formatter = new JsonFormatter();
|
||||
} else {
|
||||
formatter = new XmlFormatter();
|
||||
}
|
||||
formatter.format(new Article("Tiered Compilation in JVM", "Baeldung"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.tieredcompilation;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
|
||||
public class XmlFormatter implements Formatter {
|
||||
|
||||
private static final XmlMapper mapper = new XmlMapper();
|
||||
|
||||
@Override
|
||||
public <T> String format(T object) throws JsonProcessingException {
|
||||
return mapper.writeValueAsString(object);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue