-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
unknow-server-bench/src/main/java/unknow/server/bench/BenchDocument.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package unknow.server.bench; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.transform.TransformerConfigurationException; | ||
import javax.xml.transform.TransformerException; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.dom.DOMSource; | ||
import javax.xml.transform.stream.StreamResult; | ||
|
||
import org.apache.xmlbeans.XmlException; | ||
import org.apache.xmlbeans.XmlObject; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.w3c.dom.Document; | ||
import org.xml.sax.SAXException; | ||
|
||
public class BenchDocument { | ||
private static final ClassLoader cl = BenchDocument.class.getClassLoader(); | ||
|
||
@Benchmark | ||
public void xmlBean() throws XmlException, IOException { | ||
XmlObject o; | ||
try (InputStream is = cl.getResourceAsStream("complex.xml")) { | ||
o = XmlObject.Factory.parse(is); | ||
} | ||
|
||
o.save(DUMP); | ||
} | ||
|
||
private static final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); | ||
private static final TransformerFactory tranformer = TransformerFactory.newInstance(); | ||
|
||
@Benchmark | ||
public void document() throws SAXException, IOException, ParserConfigurationException, TransformerConfigurationException, TransformerException { | ||
Document o; | ||
try (InputStream is = cl.getResourceAsStream("complex.xml")) { | ||
o = docFactory.newDocumentBuilder().parse(is); | ||
} | ||
|
||
tranformer.newTransformer().transform(new DOMSource(o), new StreamResult(DUMP)); | ||
} | ||
|
||
private static final OutputStream DUMP = new OutputStream() { | ||
@Override | ||
public void write(int b) throws IOException { // OK | ||
} | ||
|
||
@Override | ||
public void write(byte[] b) throws IOException { // OK | ||
} | ||
|
||
@Override | ||
public void write(byte[] b, int off, int len) throws IOException { // OK | ||
} | ||
}; | ||
} |
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
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