1   /*
2    $Id$
3   
4    Copyright 2003 The Werken Company. All Rights Reserved.
5    
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are
8   met:
9   
10    * Redistributions of source code must retain the above copyright
11      notice, this list of conditions and the following disclaimer.
12  
13    * Redistributions in binary form must reproduce the above copyright
14      notice, this list of conditions and the following disclaimer in the
15      documentation and/or other materials provided with the distribution.
16  
17    * Neither the name of the Jaxen Project nor the names of its
18      contributors may be used to endorse or promote products derived 
19      from this software without specific prior written permission.
20  
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  
33   */
34  package org.jaxen.test;
35  
36  import java.net.URL;
37  
38  import org.jaxen.jdom.JDOMXPath;
39  import org.jdom.Document;
40  import org.jdom.Element;
41  import org.jdom.input.SAXBuilder;
42  
43  class JDOMPerformance {
44      
45      public static void main(String[] args) {
46          try {
47              URL u = new URL("http://www.ibiblio.org/xml/examples/shakespeare/much_ado.xml");
48              Document doc = new SAXBuilder().build(u);
49              JDOMXPath xpath = new JDOMXPath("PLAY/ACT/SCENE/SPEECH/SPEAKER");
50              
51              long start = System.currentTimeMillis();
52              
53              int count = 0;
54              for (int i = 0; i < 1000; i++) {
55                  Element speaker = (Element) xpath.selectSingleNode(doc);
56                  count += (speaker == null ? 0 : 1);
57              }
58              
59              long end = System.currentTimeMillis();
60              System.out.println((end - start));
61              System.out.println(count);
62              
63          } catch (Exception ex) {
64              ex.printStackTrace();
65          }
66      }
67      
68  }