Try running each group 100 times or so and getting the average timing; or see what happens if you run group2 first.
 
If you only run it once, group1 will incur a lot of startup overhead, for example the overhead of setting up the output destination. Also, the Java hot-spot compiler takes a while to warm up, and group2 will get all the benefits of this.
 

Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com

-----Original Message-----
From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of David Benny
Sent: 26 July 2002 19:24
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Performance issue

Hi
 
I am using saxon 6.5.2 and I am investigating some performace issues with my code.
 
The test is split into 2 parts - Group1 and Group2.
Group1 is the same as Group2 except I have removed references to namespaces in the select statements.
The xml I have supplied does not have any namespace declarations so that Group1 and Group2 process the same number of nodes.
 
When I execute the transform I get the following trace messages:
 
start 16:47:50+01:00
start GROUP1 16:47:50+01:00
end GROUP1 16:47:58+01:00
start GROUP2 16:47:58+01:00
end GROUP2 16:48:01+01:00
end 16:48:01+01:00
 
This shows that Group2 is twice the speed of Group1. Why?
 
David
 
<xsl:stylesheet version="1.1"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:date="http://exslt.org/dates-and-times
 xmlns:set="http://exslt.org/sets
 extension-element-prefixes="xsl date set">
               
<xsl:template match="document">
 <xsl:message>start <xsl:value-of select="date:time()"/></xsl:message>
 
 <xsl:message>start GROUP1 <xsl:value-of select="date:time()"/></xsl:message>
 <xsl:call-template name="group1">
  <xsl:with-param name="context"><xsl:value-of select="/.."/></xsl:with-param>
  <xsl:with-param name="startNode" select="*[1]"/>
  <xsl:with-param name="lastNode" select="*[position()=last()]"/>
 </xsl:call-template>
 <xsl:message>end GROUP1 <xsl:value-of select="date:time()"/></xsl:message>
 
 <xsl:message>start GROUP2 <xsl:value-of select="date:time()"/></xsl:message>
 <xsl:call-template name="group2">
  <xsl:with-param name="context"><xsl:value-of select="/.."/></xsl:with-param>
  <xsl:with-param name="startNode" select="*[1]"/>
  <xsl:with-param name="lastNode" select="*[position()=last()]"/>
 </xsl:call-template>
 <xsl:message>end GROUP2 <xsl:value-of select="date:time()"/></xsl:message>
 
 <xsl:message>end <xsl:value-of select="date:time()"/></xsl:message>
</xsl:template>
 
<xsl:template name="group1">
 <xsl:param name="context"/>
 <xsl:param name="startNode"/>
 <xsl:param name="lastNode"/>
 <xsl:choose>
  <xsl:when test="
   $startNode[self::w and @esc=false()][string(number($startNode))!='NaN' and
   following::text()[1][normalize-space(substring(.,1,1))='']]
   ">
   <xsl:variable name="endNode" select="(
    set:leading($startNode/following-sibling::w[@esc=false()][string(number(.))!='NaN' and $startNode>=. and
     following::text()[1][normalize-space(substring(.,1,1))=''] and preceding-sibling::*[namespace-uri()=''][1][not(self::k and .='LENGTH')]][1]
     /preceding-sibling::*[namespace-uri()=''][1],$lastNode) |
    $lastNode
    )[1]
    "/>
   <xsl:variable name="nextStartNode" select="set:leading($endNode/following::*[1],$lastNode)"/>
   <xsl:call-template name="group1">
    <xsl:with-param name="context" select="$context"/>
    <xsl:with-param name="startNode" select="$nextStartNode"/>
    <xsl:with-param name="lastNode" select="$lastNode"/>
   </xsl:call-template>
  </xsl:when>
 </xsl:choose>
</xsl:template>
 
<xsl:template name="group2">
 <xsl:param name="context"/>
 <xsl:param name="startNode"/>
 <xsl:param name="lastNode"/>
 <xsl:choose>
  <xsl:when test="
   $startNode[self::w and @esc=false()][string(number($startNode))!='NaN' and
   following::text()[1][normalize-space(substring(.,1,1))='']]
   ">
   <xsl:variable name="endNode" select="(
    set:leading($startNode/following-sibling::w[@esc=false()][string(number(.))!='NaN' and $startNode>=. and
     following::text()[1][normalize-space(substring(.,1,1))=''] and preceding-sibling::*[1][not(self::k and .='LENGTH')]][1]
     /preceding-sibling::*[1],$lastNode) |
    $lastNode
    )[1]
    "/>
   <xsl:variable name="nextStartNode" select="set:leading($endNode/following::*[1],$lastNode)"/>
   <xsl:call-template name="group2">
    <xsl:with-param name="context" select="$context"/>
    <xsl:with-param name="startNode" select="$nextStartNode"/>
    <xsl:with-param name="lastNode" select="$lastNode"/>
   </xsl:call-template>
  </xsl:when>
 </xsl:choose>
</xsl:template>
 
</xsl:stylesheet>
 
<?xml version="1.0" encoding="utf-8"?><document xml:space="preserve" natural="">
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000<w>1</w>   
0000</document>