Unexpected quadratic execution time
With the following content in p.xsl:
<stylesheet version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform">
<output method="text"/>
<template name="c">
<param name="str"/>
<value-of select="$str"/>
</template>
<template name="a">a</template>
<template name="loop">
<param name="s"/>
<param name="e"/>
<if test="$s <= $e">
<call-template name="c">
<!-- quadratic -->
<!--
<with-param name="str">
<call-template name="a"/>
</with-param>
-->
<!-- linear -->
<with-param name="str" select="'a'"/>
</call-template>
<variable name="m" select="floor(($s + $e) div 2)"/>
<call-template name="loop">
<with-param name="s" select="$s + 1" />
<with-param name="e" select="$m" />
</call-template>
<call-template name="loop">
<with-param name="s" select="$m + 1" />
<with-param name="e" select="$e" />
</call-template>
</if>
</template>
<template match="/">
<call-template name="loop">
<with-param name="s" select="1"/>
<with-param name="e" select="1000000"/>
</call-template>
</template>
</stylesheet>
I get quadratic or linear execution times depending on which argument passing is commented out:
time xsltproc p.xsl p.xsl > p.out
real 5m16,605s
user 5m16,592s
sys 0m0,004s
Passing the result of template 'a' to 'c'.
time xsltproc p.xsl p.xsl > q.out
real 0m1,935s
user 0m1,935s
sys 0m0,000s
Passing directly the string 'a' to 'c'.
Of course increasing the number of iterations the quadratic variant takes ages.
From my analysis of code it seems that the quadratic variant keeps recomputing the output length (no idea why).