View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.html.performance;
16  
17  import java.io.IOException;
18  import java.net.URL;
19  
20  import org.htmlunit.BrowserVersion;
21  import org.htmlunit.WebClient;
22  
23  /**
24   * Tests for handling huge content.
25   *
26   * @author Ronald Brill
27   */
28  public final class HugePagePerformanceTest {
29  
30      private HugePagePerformanceTest() {
31      }
32  
33      /**
34       * Simple main for the moment.
35       * @param args ignored
36       * @throws IOException in case of error
37       */
38      public static void main(final String[] args) throws IOException {
39  //        final URL fileURL = WebClient.class.getClassLoader()
40  //                .getResource("testfiles/huge-pages/html-standard-2024-10-17.html");
41          final URL benchmarkFileURL = WebClient.class.getClassLoader()
42                  .getResource("testfiles/huge-pages/benchmark.html");
43          final URL htmlStandardfileURL = WebClient.class.getClassLoader()
44                  .getResource("testfiles/huge-pages/html-standard-2024-10-17.html");
45          final URL wikipediaURL = WebClient.class.getClassLoader()
46                  .getResource("testfiles/huge-pages/wikipedia.html");
47  
48          try (WebClient webClient = new WebClient(BrowserVersion.CHROME, false, null, -1)) {
49              webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
50              webClient.getOptions().setJavaScriptEnabled(false);
51              webClient.getOptions().setCssEnabled(false);
52              webClient.getOptions().setHistoryPageCacheLimit(0);
53              webClient.getOptions().setHistorySizeLimit(0);
54              webClient.getOptions().setWebSocketEnabled(false);
55              webClient.setFrameContentHandler(baseFrameElement -> false);
56  
57              final long start = System.currentTimeMillis();
58  
59  //            for (int i = 0; i < 20000; i++) {
60  //                webClient.getPage(benchmarkFileURL);
61  //            }
62  
63              for (int i = 0; i < 40; i++) {
64                  webClient.getPage(htmlStandardfileURL);
65              }
66  
67  //            for (int i = 0; i < 10000; i++) {
68  //                webClient.getPage(wikipediaURL);
69  //            }
70  
71              System.out.println("## " + (System.currentTimeMillis() - start));
72          }
73      }
74  }