[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Recursion performance (fibonacci numbers)

Subject: Recursion performance (fibonacci numbers)
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Mon, 16 Jan 2006 20:38:11 +0530
 Recursion performance (fibonacci numbers)
Dear All,
   I am running this XSLT stylesheet with Saxon b 8.6.1. This prints
1st n Fibonacci numbers, where n is supplied as a stylesheet
parameter.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:myfunc="http://dummy"
                version="2.0">

<xsl:output method="text" />

<xsl:param name="n" />

<xsl:template match="/">
  <xsl:for-each select="1 to $n">
    <xsl:value-of select="myfunc:fibonacci(position())" /><xsl:text>
</xsl:text>
  </xsl:for-each>
</xsl:template>

<xsl:function name="myfunc:fibonacci" as="xs:integer">
  <xsl:param name="n" as="xs:integer" />

  <xsl:sequence select="if (($n = 1) or ($n = 2))
                        then
                          1
                        else
                          (myfunc:fibonacci($n - 1) + myfunc:fibonacci($n -
2))"
                       />

</xsl:function>

</xsl:stylesheet>

The problem is, that it takes long time for large values of n. I
observed the following timing

n=32 -> 35.5 secs
n=33 -> 55.2 secs
n=34 -> 1 min 27.3 secs
n=35 -> 2 mins 20.1 secs

Is it possible I can improve the performance of this stylesheet for
large values of n?

Regards,
Mukul

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.