From 3d6b368c11069b65eac4446a018f7539a6a4566e Mon Sep 17 00:00:00 2001 From: Alon Harel Date: Wed, 2 Oct 2024 03:05:07 +0300 Subject: [PATCH 1/3] add jmh test --- pom.xml | 18 + .../util/XmlUtilsSunXercesHelper.java | 4 +- .../java/org/htmlunit/SimpleWebTestCase.java | 4 + .../benchmarks/HtmlUnitBenchmark.java | 633 ++++++++++++++++++ 4 files changed, 657 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java diff --git a/pom.xml b/pom.xml index 93bb4fbc11c..1b27213badf 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,8 @@ **/CodeChecker.java + 15 + 15 @@ -1200,6 +1202,22 @@ + + xerces + xercesImpl + 2.12.2 + + + org.openjdk.jmh + jmh-core + 1.37 + + + org.openjdk.jmh + jmh-generator-annprocess + 1.37 + provided + org.apache.httpcomponents diff --git a/src/main/java/org/htmlunit/platform/util/XmlUtilsSunXercesHelper.java b/src/main/java/org/htmlunit/platform/util/XmlUtilsSunXercesHelper.java index f4594f149b1..c0150dff886 100644 --- a/src/main/java/org/htmlunit/platform/util/XmlUtilsSunXercesHelper.java +++ b/src/main/java/org/htmlunit/platform/util/XmlUtilsSunXercesHelper.java @@ -20,13 +20,13 @@ import java.util.Map; import java.util.Objects; +import org.apache.xerces.dom.DeferredDocumentImpl; +import org.apache.xerces.dom.DeferredNode; import org.htmlunit.platform.XmlUtilsHelperAPI; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl; -import com.sun.org.apache.xerces.internal.dom.DeferredNode; /** * INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
diff --git a/src/test/java/org/htmlunit/SimpleWebTestCase.java b/src/test/java/org/htmlunit/SimpleWebTestCase.java index c8766ab7bcd..27da4a3310f 100644 --- a/src/test/java/org/htmlunit/SimpleWebTestCase.java +++ b/src/test/java/org/htmlunit/SimpleWebTestCase.java @@ -56,6 +56,10 @@ public final HtmlPage loadPage(final String html) throws Exception { return loadPage(html, null); } + public final HtmlPage loadPageOnlyParse(final String html) throws Exception { + return loadPage(html, null); + } + /** * User the default browser version to load a page with the specified HTML * and collect alerts into the list. diff --git a/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java b/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java new file mode 100644 index 00000000000..700a18da443 --- /dev/null +++ b/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java @@ -0,0 +1,633 @@ +package org.htmlunit.benchmarks; + +import java.util.concurrent.TimeUnit; + +import org.htmlunit.BrowserVersion; +import org.htmlunit.SimpleWebTestCase; +import org.htmlunit.WebClient; +import org.htmlunit.html.HtmlPage; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Timeout; +import org.openjdk.jmh.annotations.Warmup; + +@State(Scope.Benchmark) +public class HtmlUnitBenchmark extends SimpleWebTestCase { + + String html = """ + + + + +
+ + +
+
+
+
+
+
+

+ + Stella Levinson + +

+
+
+

+ + Project manager + +

+
+
+

+ + Looking for my next opportunity to make a change. The digital way. + +

+
+ +
+
+
+ + + +
+
+
+
+
+
+
+
+ +
+
+
+
+

+ + I advise companies and NGOs in initiatives and campaigns + +

+
+
+

+ + For more than 15 years, I've been working with international clients on a range of projects, gathering experience in diverse areas. I look forward to hearing about your project and plan its success together.  + +

+
+ + + + + + + SEE RESUME + + +
+
+
+
+
+
+
+

+ + Recommendations + +

+
+
+ +
+
+
+
+
+
+
+
+

+ + Work Experience + +

+
+
+
+
+
+
+
+
+
+ + 2020-2021 + +
+
+
+

+ + Advisor, South Company + +

+
+
+
+
+

+ + In this position, I led a team of more than 40 professional and volunteer staff members, from various company departments.  + + + + + +

+
+
+
+
+
+
+
+
+
+ + 2019-2020 + +
+
+
+

+ + Consultant, North Company + +

+
+
+
+
+

+ + In this position, I led a team of more than 40 professional and volunteer staff members, from various company departments.  + +

+
+
+
+
+
+
+
+
+
+ + 2018-2019 + +
+
+
+

+ + Project manager, East Company + +

+
+
+
+
+

+ + + In this position, I led a team of more than 40 professional and volunteer staff members, from various company departments. + + +

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ + Education + +

+
+
+
+
+
+ + 2014-2018 + +
+
+
+

+ + New York University + +

+
+
+

+ + + MBA in International Studies and Economics + + +

+
+
+
+ + 2010-2014 + +
+
+
+

+ + Texas University + +

+
+
+

+ + Bachelor of Arts in International Studies (BAIS) + +

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ + Professional skills + +

+
+
+
+
+

+ + Entrepreneurial Mindset + +

+
+
+

+ + Go-to-Market Planning + +

+
+
+
+
+

+ + Teamwork & Collaboration + +

+
+
+

+ + Digital Analytics + +

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ + Languages + +

+
+
+
+
+

+ + English + +

+
+
+

+ + French + +

+
+
+
+
+

+ + Dutch + +

+
+
+

+ + Spanish + +

+
+
+
+
+
+
+
+
+

+ + Get in Touch + +

+
+
+

+ + + Want to hear more about how I can help your project succeed. Send me an email or call me and let's talk about your needs. + + +

+
+
+

+ + Call: 123-456-7890 + +

+

+ +
+
+

+

+ + Write: info@mysite.com + +

+
+ + +
+
+
+

+

+
+
+
+ + + +
+
+ + + +
+
+ + + +
+ + +
+ +
+ + + + +
+
+ + +
+
+
+
+
+
+
+ + + + + """; + + @Benchmark + @Fork(2) + @Warmup(iterations = 3) + @Timeout(time = 1000) + @Measurement(iterations = 4) + @BenchmarkMode(Mode.All) + public void JMH() throws Exception { + + setBrowserVersion(BrowserVersion.CHROME); + + HtmlPage pageFromString = loadPage( html); + + assert !pageFromString.querySelector("h1").asNormalizedText().contains("Stella"); + } + +} From 0d9d35851a76120afab0198ad8b5fc5d4b646eec Mon Sep 17 00:00:00 2001 From: Alon Harel Date: Wed, 2 Oct 2024 03:07:59 +0300 Subject: [PATCH 2/3] add jmh test --- .../benchmarks/HtmlUnitBenchmark.java | 151 +++++++++++++++++- 1 file changed, 147 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java b/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java index 700a18da443..79709c943ba 100644 --- a/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java +++ b/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java @@ -1,10 +1,7 @@ package org.htmlunit.benchmarks; -import java.util.concurrent.TimeUnit; - import org.htmlunit.BrowserVersion; import org.htmlunit.SimpleWebTestCase; -import org.htmlunit.WebClient; import org.htmlunit.html.HtmlPage; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -53,6 +50,16 @@ public class HtmlUnitBenchmark extends SimpleWebTestCase { Project manager + + Project manager + + + Project manager + + Project manager + + +
@@ -321,9 +328,38 @@ public class HtmlUnitBenchmark extends SimpleWebTestCase {

Project manager, East Company + +

+
+

+ + Project manager, East Company + +

+

+ + Project manager, East Company + +

+

+ + Project manager, East Company + +

+

+ + Project manager, East Company + +

+

+ + Project manager, East Company

+ + +
@@ -380,6 +416,92 @@ public class HtmlUnitBenchmark extends SimpleWebTestCase { MBA in International Studies and Economics + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + +

@@ -496,6 +618,27 @@ Bachelor of Arts in International Studies (BAIS)
+ + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + + MBA in International Studies and Economics + + + + MBA in International Studies and Economics + + + +

@@ -625,7 +768,7 @@ public void JMH() throws Exception { setBrowserVersion(BrowserVersion.CHROME); - HtmlPage pageFromString = loadPage( html); + HtmlPage pageFromString = loadPage(html); assert !pageFromString.querySelector("h1").asNormalizedText().contains("Stella"); } From fe1282a1a1c30695be16db35865bcd41cc2bdd87 Mon Sep 17 00:00:00 2001 From: Alon Harel Date: Mon, 21 Oct 2024 11:49:18 +0300 Subject: [PATCH 3/3] remove unused code --- src/test/java/org/htmlunit/SimpleWebTestCase.java | 4 ---- .../org/htmlunit/benchmarks/HtmlUnitBenchmark.java | 14 +++++++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/htmlunit/SimpleWebTestCase.java b/src/test/java/org/htmlunit/SimpleWebTestCase.java index 27da4a3310f..c8766ab7bcd 100644 --- a/src/test/java/org/htmlunit/SimpleWebTestCase.java +++ b/src/test/java/org/htmlunit/SimpleWebTestCase.java @@ -56,10 +56,6 @@ public final HtmlPage loadPage(final String html) throws Exception { return loadPage(html, null); } - public final HtmlPage loadPageOnlyParse(final String html) throws Exception { - return loadPage(html, null); - } - /** * User the default browser version to load a page with the specified HTML * and collect alerts into the list. diff --git a/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java b/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java index 79709c943ba..07a03ccda9e 100644 --- a/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java +++ b/src/test/java/org/htmlunit/benchmarks/HtmlUnitBenchmark.java @@ -2,6 +2,7 @@ import org.htmlunit.BrowserVersion; import org.htmlunit.SimpleWebTestCase; +import org.htmlunit.WebClient; import org.htmlunit.html.HtmlPage; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -759,7 +760,7 @@ Bachelor of Arts in International Studies (BAIS) """; @Benchmark - @Fork(2) + @Fork(1) @Warmup(iterations = 3) @Timeout(time = 1000) @Measurement(iterations = 4) @@ -767,8 +768,15 @@ Bachelor of Arts in International Studies (BAIS) public void JMH() throws Exception { setBrowserVersion(BrowserVersion.CHROME); - - HtmlPage pageFromString = loadPage(html); + WebClient webClient = new WebClient(BrowserVersion.getDefault(), false, null, -1); + webClient.getOptions().setJavaScriptEnabled(false); + webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); + webClient.getOptions().setCssEnabled(false); + webClient.getOptions().setHistoryPageCacheLimit(0); + webClient.getOptions().setHistorySizeLimit(0); + webClient.getOptions().setWebSocketEnabled(false); + webClient.setFrameContentHandler(baseFrameElement -> false); + HtmlPage pageFromString = loadPage(webClient, html, null, URL_FIRST); assert !pageFromString.querySelector("h1").asNormalizedText().contains("Stella"); }