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

RE: String conversion problem when string is large

Subject: RE: String conversion problem when string is large
From: "Bulgrien, Kevin" <Kevin.Bulgrien@xxxxxxxxxxxx>
Date: Wed, 21 Mar 2012 17:18:38 -0500
RE:  String conversion problem when string is large
And this variant seems to balance speed and memory usage, but still kills all
the engines I have except the Saxonica engine.

Execution time: 1.039s (1039ms)
Memory used: 30306880

<xsl:call-template name="HexToDec">
  <xsl:with-param name="HexData" select="." />
  <xsl:with-param name="Hex" select="'0123456789ABCDEF'" />
</xsl:call-template>

<xsl:template name="HexToDec">
  <xsl:param name="HexData" />
  <xsl:param name="Hex" />
  <xsl:if test="string-length($HexData) &gt; 0">
    <xsl:text>,</xsl:text>
    <xsl:value-of
      select="string-length(
                substring-before(
                  $Hex, substring($HexData, 3, 1))) * 16 +
              string-length(
                  substring-before(
                  $Hex, substring($HexData, 4, 1)))" />
    <xsl:call-template name="HexToDec">
      <xsl:with-param name="HexData"
        select="substring-after($HexData, ',')" />
      <xsl:with-param name="Hex" select="$Hex" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

To let other XSLT engines that do not optimize recursion, a divide and conquer
approach was simple enough to concoct.  The chunk size was a bit arbitrary,
but is about half of what it took to break another engine at its default stack
depth.  xsltproc took about 2.8 seconds.  sablotron took 5.8 seconds.  I won't
bother to show times for the Windows engines as the platform difference makes
them hard to compare fairly.

Execution time: 832ms
Memory used: 26545336

<xsl:call-template name="HexToDecChunker">
  <xsl:with-param name="HexData" select="." />
  <xsl:with-param name="Hex" select="'0123456789ABCDEF'" />
</xsl:call-template>

<xsl:template name="HexToDecChunker">
  <xsl:param  name="HexData" />
  <xsl:param name="Hex" />
  <xsl:variable name="ChunkLen" select="5120" />
  <xsl:variable name="InputLen" select="string-length($HexData)" />
  <xsl:choose>
    <xsl:when test="$InputLen &gt; $ChunkLen">
      <xsl:call-template name="HexToDec">
        <xsl:with-param name="HexData"
          select="substring($HexData, 1, $ChunkLen)" />
        <xsl:with-param name="Hex" select="$Hex" />
      </xsl:call-template>
      <xsl:call-template name="HexToDecChunker">
        <xsl:with-param name="HexData"
          select="substring($HexData, $ChunkLen + 1)" />
        <xsl:with-param name="Hex" select="$Hex" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="HexToDec">
        <xsl:with-param name="HexData" select="$HexData" />
        <xsl:with-param name="Hex" select="$Hex" />
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

What an adventure.  There are probably a lot more ways to tackle this issue.

Kevin Bulgrien

This message and/or attachments may include information subject to GD
Corporate Policy 07-105 and is intended to be accessed only by authorized
personnel of General Dynamics and approved service providers.  Use, storage
and transmission are governed by General Dynamics and its policies.
Contractual restrictions apply to third parties.  Recipients should refer to
the policies or contract to determine proper handling.  Unauthorized review,
use, disclosure or distribution is prohibited.  If you are not an intended
recipient, please contact the sender and destroy all copies of the original
message.

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.