Note that there are some explanatory texts on larger screens.

plurals
  1. POJsoup: Performance of top-level select() vs. inner-level select()
    primarykey
    data
    text
    <p>My understanding is that once a document is loaded into Jsoup, using <code>Jsoup.parse()</code>, no parsing is required again as a neatly hierarchical tree is ready for programmer's use.</p> <p>But what I am not sure whether top-level select() is more costly than inner-level select().</p> <p>For example, if we have a <code>&lt;p&gt;</code> buried inside many nested <code>&lt;div&gt;</code>s, and that <code>&lt;p&gt;</code>'s parent is already available in the program, will there be <em>any</em> performance difference between:</p> <pre><code>document.select("p.pclass") </code></pre> <p>and</p> <pre><code>pImediateParent.select("p.pclass") </code></pre> <p>?</p> <p>How does that work in Jsoup?</p> <p><strong>UPDATE:</strong> Based on the answer below, I understand that both <code>document.select()</code> and <code>pImediateParent.select()</code> use the <a href="http://massapi.com/source/jsoup-1.6.1-sources/org/jsoup/nodes/Element.java.html" rel="nofollow">same exact static method</a>, just with a different root as the second parameter:</p> <pre><code>public Elements select(String query) { return Selector.select(query, this); } </code></pre> <p>Which <a href="http://massapi.com/source/jsoup-1.6.1-sources/org/jsoup/select/Selector.java.html" rel="nofollow">translates into</a>:</p> <pre><code>/** * Find elements matching selector. * * @param query CSS selector * @param root root element to descend into * @return matching elements, empty if not */ public static Elements select(String query, Element root) { return new Selector(query, root).select(); } </code></pre> <p>I am not surprised, but the question now is how does that <code>query</code> work? Does it iterate to find the queried element? Is it a random access (as in hash table) query?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload