Skip to content

Commit 34798ad

Browse files
committedNov 19, 2020
Add "Benchmarks" section.
1 parent 5a80625 commit 34798ad

23 files changed

+566
-27
lines changed
 

‎basic-b.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎benchmark/html-build.png

22.5 KB
Loading

‎benchmark/sac-226kb.png

16.7 KB
Loading

‎benchmark/sac-small.png

18.2 KB
Loading

‎benchmark/xml-build-small.png

23.4 KB
Loading

‎benchmark/xml-build.png

22.6 KB
Loading

‎benchmarks.html

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>CSS4J benchmarks</title>
5+
<link href="basic-b.css" rel="stylesheet" type="text/css" />
6+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
</head>
9+
<body id="benchmarks">
10+
<div class="layout">
11+
<div id="hdr01"></div>
12+
<a id="mylinkhome" href="/"><span>CSS4J</span></a>
13+
</div>
14+
<div class="container">
15+
<div class="menu">
16+
<ul class="menulist">
17+
<li><a id="mnuindice" href="/"><span>Home</span></a></li>
18+
<li><a id="mnuusage" href="usage.html"><span>Usage</span></a></li>
19+
<li><a id="mnuapi2" href="api/3/"><span>API 3.x</span></a></li>
20+
<li><a id="mnufaq" href="faq.html"><span>FAQ</span></a></li>
21+
<li><div id="mnubenchmarks-sel"><span>Benchmarks</span></div></li>
22+
<li class="menulvl2"><a id="mnudommark" href="dom-mark.html"><span>DOM mark</span></a></li>
23+
<li class="menulvl2"><a id="mnusacmark" href="sac-mark.html"><span>SAC mark</span></a></li>
24+
<li><a id="mnugithub" href="https://github.com/css4j"><span>Github</span></a></li>
25+
</ul>
26+
</div>
27+
<div class="beforemain"></div>
28+
<div class="main">
29+
<div id="presentacion_top" class="textheader"><span>Benchmarks</span></div>
30+
<div class="cos">
31+
<h2>CSS4J benchmarks</h2>
32+
<p>The <a href="https://github.com/css4j/benchmark">benchmark</a> repository contains several <a href="https://openjdk.java.net/projects/code-tools/jmh/">JMH</a> benchmarks used during the development of the library,
33+
which can be executed with commands like:</p>
34+
<pre class="code">java -jar build/benchmarks.jar XMLBuildBenchmark -rf json
35+
</pre>
36+
<p>Here are some results from them:</p>
37+
<ul>
38+
<li><a href="dom-mark.html">DOM benchmarks</a>.</li>
39+
<li><a href="sac-mark.html">SAC benchmark (css4j 1.x only)</a>.</li>
40+
</ul>
41+
</div>
42+
<div class="footnote">
43+
</div>
44+
</div>
45+
</div>
46+
</body>
47+
</html>

‎common.css

+45-1
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,30 @@ body .menu {
8282
padding: 1px 0 0 0.2ex;
8383
}
8484

85+
li.menulvl2 a, li.menulvl2 div
86+
{
87+
height: 20px;
88+
padding: 0 0 0 0.7ex;
89+
}
90+
8591
.menulist a
8692
{
8793
display: block;
8894
background: url(imag/mnubg_a.png) no-repeat;
8995
}
9096

97+
li.menulvl2 a
98+
{
99+
display: block;
100+
background: url(imag/mnubg2_a.png) no-repeat;
101+
}
102+
103+
li.menulvl2 a:hover
104+
{
105+
text-align: right;
106+
background: url(imag/mnubg2_b.png) no-repeat;
107+
}
108+
91109
.menulist a:hover
92110
{
93111
text-align: right;
@@ -172,6 +190,11 @@ pre
172190
font-size: 1.4em;
173191
}
174192

193+
pre.code
194+
{
195+
background-color: #e7e4de;
196+
}
197+
175198
div.tema
176199
{
177200
margin: 2em 0 3.3em 0;
@@ -207,7 +230,28 @@ img.diagram
207230
list-style-type: square;
208231
}
209232

210-
.legalremind
233+
.normaltbl td, .normaltbl th
234+
{
235+
padding: 0.4em 1em 0.5em 1.1em;
236+
}
237+
238+
.normaltbl th
239+
{
240+
white-space: nowrap;
241+
text-align: center;
242+
}
243+
244+
.normaltbl td.number
245+
{
246+
text-align: right;
247+
}
248+
249+
.normaltbl th:first-child
250+
{
251+
text-align: left;
252+
}
253+
254+
.note,.legalremind
211255
{
212256
font-size: smaller;
213257
font-style: italic;

‎dom-mark.html

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>CSS4J DOM benchmarks</title>
5+
<link href="basic-b.css" rel="stylesheet" type="text/css" />
6+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
</head>
9+
<body id="dom-mark">
10+
<div class="layout">
11+
<div id="hdr01"></div>
12+
<a id="mylinkhome" href="/"><span>CSS4J</span></a>
13+
</div>
14+
<div class="container">
15+
<div class="menu">
16+
<ul class="menulist">
17+
<li><a id="mnuindice" href="/"><span>Home</span></a></li>
18+
<li><a id="mnuusage" href="usage.html"><span>Usage</span></a></li>
19+
<li><a id="mnuapi2" href="api/3/"><span>API 3.x</span></a></li>
20+
<li><a id="mnufaq" href="faq.html"><span>FAQ</span></a></li>
21+
<li><a id="mnubenchmarks" href="benchmarks.html"><span>Benchmarks</span></a></li>
22+
<li class="menulvl2"><div id="mnudommark-sel"><span>DOM mark</span></div></li>
23+
<li class="menulvl2"><a id="mnusacmark" href="sac-mark.html"><span>SAC mark</span></a></li>
24+
<li><a id="mnugithub" href="https://github.com/css4j"><span>Github</span></a></li>
25+
</ul>
26+
</div>
27+
<div class="beforemain"></div>
28+
<div class="main">
29+
<div id="presentacion_top" class="textheader"><span>DOM mark</span></div>
30+
<div class="cos">
31+
<h1>DOM benchmarks</h1>
32+
<div class="tema" id="overview">
33+
<h2>Overview</h2>
34+
<p>The DOM benchmarks measure how fast different DOM implementations are when building documents. The following software versions were used:</p>
35+
<ul>
36+
<li>Java: <a href="https://adoptopenjdk.net/">AdoptOpenJDK</a>* 15.</li>
37+
<li>JMH: 1.26.</li>
38+
<li>css4j: 3.2 (pre-release).</li>
39+
<li>validator.nu htmlparser: <a href="https://search.maven.org/artifact/nu.validator/htmlparser">1.4.16</a>.</li>
40+
</ul>
41+
<p>The computer has an Intel® Core™ i5-1035G7 CPU and 8GB of RAM.</p>
42+
<p class="note">(*) Note: one of the tested DOM implementations is the one that comes bundled with the JDK (identified as "JDK" in the graphics), and it has been observed
43+
that the version shipped with the Oracle JDK may be faster.</p>
44+
</div>
45+
<div class="tema" id="html-mark">
46+
<h2>Build HTML documents</h2>
47+
<p>Measures the speed at which the <a href="https://about.validator.nu/htmlparser/">validator.nu HTML parser</a> can build a small document (38 KB HTML) into a few DOM implementations.</p>
48+
<img src="benchmark/html-build.png" alt="HTML build benchmark" />
49+
<p>Numeric results (higher is better):</p>
50+
<table class="normaltbl">
51+
<tr><th>Implementation</th><th>Score</th><th>Error</th><th>Unit</th></tr>
52+
<tr><td>Css4j-DOM4J</td><td class="number">335,609</td><td class="number">±9,416</td><td>ops/s</td></tr>
53+
<tr><td>Css4j DOM</td><td class="number">328,637</td><td class="number">±1,920</td><td>ops/s</td></tr>
54+
<tr><td>JDK</td><td class="number">333,742</td><td class="number">±3,079</td><td>ops/s</td></tr>
55+
</table>
56+
<p>If one looks at the error figures, the three implementations are somewhat even in this test.</p>
57+
</div>
58+
<div class="tema" id="xml-small-mark">
59+
<h2>Build small XML documents</h2>
60+
<p>The SAX parser that comes bundled with the JDK is used to parse and build a document from a small XHTML file (38 KB).</p>
61+
<img src="benchmark/xml-build-small.png" alt="XML build benchmark (small file)" />
62+
<p>Numeric results (higher is better):</p>
63+
<table class="normaltbl">
64+
<tr><th>Implementation</th><th>Score</th><th>Error</th><th>Unit</th></tr>
65+
<tr><td>Css4j-DOM4J</td><td class="number">496,924</td><td class="number">±3,864</td><td>ops/s</td></tr>
66+
<tr><td>Css4j DOM</td><td class="number">447,644</td><td class="number">±7,290</td><td>ops/s</td></tr>
67+
<tr><td>DOM4J</td><td class="number">520,322</td><td class="number">±1,193</td><td>ops/s</td></tr>
68+
<tr><td>JDK</td><td class="number">507,176</td><td class="number">±6,105</td><td>ops/s</td></tr>
69+
</table>
70+
</div>
71+
<div class="tema" id="xml-small-mark">
72+
<h2>Build XML documents</h2>
73+
<p>The SAX parser that comes bundled with the JDK is used to parse and build a document (1MB file).</p>
74+
<img src="benchmark/xml-build.png" alt="XML build benchmark" />
75+
<p>Numeric results (higher is better):</p>
76+
<table class="normaltbl">
77+
<tr><th>Implementation</th><th>Score</th><th>Error</th><th>Unit</th></tr>
78+
<tr><td>Css4j-DOM4J</td><td class="number">92,285</td><td class="number">±3,441</td><td>ops/s</td></tr>
79+
<tr><td>Css4j DOM</td><td class="number">76,500</td><td class="number">±0,630</td><td>ops/s</td></tr>
80+
<tr><td>DOM4J</td><td class="number">106,743</td><td class="number">±0,852</td><td>ops/s</td></tr>
81+
<tr><td>JDK</td><td class="number">113,399</td><td class="number">±1,531</td><td>ops/s</td></tr>
82+
</table>
83+
</div>
84+
<div class="tema" id="analysis">
85+
<h2>Analysis</h2>
86+
<p>DOM4J (both plain DOM4J and the CSS-enabled subclasses that CSS4J provide) is fast, but has an important scalability problem. If you use
87+
instances of DOM4J simultaneously in the same JVM, contention happens even if no common resources are explicitly accessed. This is due to DOM4J using a <code>static</code> synchronized cache of <code>QName</code> objects,
88+
as shown by the benchmark profiler (e.g. <code>java -jar build/benchmarks.jar XMLBuildBenchmark -prof stack:lines=5;top=3;detailLine=true;period=1</code>):</p>
89+
<pre class="code">Secondary result "io.sf.carte.doc.style.css.mark.XMLBuildBenchmark.markBuildDOM4J: stack":
90+
Stack profiler:
91+
92+
....[Thread state distributions]....................................................................
93+
72,3% BLOCKED
94+
27,6% RUNNABLE
95+
96+
....[Thread state: BLOCKED].........................................................................
97+
72,3% 100,0% java.util.Collections$SynchronizedMap.get
98+
org.dom4j.tree.QNameCache.get
99+
org.dom4j.DocumentFactory.createQName
100+
org.dom4j.tree.NamespaceStack.createQName
101+
org.dom4j.tree.NamespaceStack.pushQName
102+
</pre>
103+
<p>So its usage is not recommended for multi-core systems.</p>
104+
<p>DOM implementations that are CSS-enabled (like Css4j-DOM4j and Css4j's native DOM) are necessarily a bit slower than plain DOM, and Css4j's native DOM is the slowest of the
105+
measured implementations (especially when processing large XML files). More benchmarks are needed to verify that the balance of optimizations/implementation decisions in the native DOM is adequate, and try to improve its performance.</p>
106+
</div>
107+
</div>
108+
<div class="footnote">
109+
</div>
110+
</div>
111+
</div>
112+
</body>
113+
</html>

‎faq-b.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎faq.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<title>CSS4J FAQ</title>
5-
<link href="faq-a.css" rel="stylesheet" type="text/css" />
5+
<link href="faq-b.css" rel="stylesheet" type="text/css" />
66
<script src="js/faq-a.js" type="text/javascript" charset="utf-8"></script>
77
<meta http-equiv="content-type" content="text/html; charset=utf-8">
88
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -19,6 +19,7 @@
1919
<li><a id="mnuusage" href="usage.html"><span>Usage</span></a></li>
2020
<li><a id="mnuapi2" href="api/3/"><span>API 3.x</span></a></li>
2121
<li><div id="mnufaq-sel"><span>FAQ</span></div></li>
22+
<li><a id="mnubenchmarks" href="benchmarks.html"><span>Benchmarks</span></a></li>
2223
<li><a id="mnugithub" href="https://github.com/css4j"><span>Github</span></a></li>
2324
</ul>
2425
</div>

‎imag/mnubg2_a.png

398 Bytes
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.