This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: RE: How to filter characters from a string?
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Sat, 30 Mar 2002 07:51:29 -0800 (PST)
- Subject: [xsl] Re: RE: How to filter characters from a string?
- Reply-to: xsl-list at lists dot mulberrytech dot com
It seems that my first timing results were not too accurate.
I said that the str-filter()-based algorithm overtook the double
translate at string length of around 45K, actually this happens much
earlier -- at a little more than string length of 20K.
The table bellow contains more detailed results:
90K 45K 20K 10K
------------------------------------------------------------------------
str-filter: 1.247 0.648 0.286 0.140
double translate: 11.578 1.334 0.259 0.063
Cheers,
Dimitre Novatchev.
--- Dimitre Novatchev <dnovatchev@yahoo.com> wrote:
> Greg Faron <gfaron at integretechpub dot com> wrote:
>
> > At 02:11 PM 3/29/2002, you wrote:
> > >Write a translate that removes all the characters that are allowed
> in
> > >base64. The result of this translate is a string containing all
> the
> > >characters that aren't allowed, i.e. the ones you want to remove.
> > > Use this as the second parameter for another translate():
> > >
> > >translate($x, translate($x, 'ABCDE...abcde...12345...', ''), '')
> >
> > Oooh, I like that one. This way the second translate() is
> > customized for every argument, but easily coded (and maintained).
> Do
>
> > you know of any way to benchmark Microsoft XSLT operations so that
> I
> > could see which is faster? I suspect that the double translate()
> is
> > better than the template solution posted earlier.
>
> Mike's solution is fantastic -- extremely nice and elegant!
>
> On the other side, double translate means two passes over the string.
> Even if Mike's algorithm is coded in Assembler, it will be slower
> than
> a one-pass algorithm for fairly big strings.
>
> I checked this statement and it is true. Compared to the str-filter()
> (a DVC variant) the double translate is lightningly faster for very
> short strings, but its execution time grows very steeply when the
> input
> string is doubled.
>
> So, at length of around 45000 characters the str-filter() - based
> transformation overtook the double translate. The results in seconds
> were:
>
> str-filter() double-translate()
> ----------- ------------------
> 1.095 1.308
>
>
> This was measured on a P4 1.7GHz 256MB RAM with MSXML4.
>
> For strings with this length or longer, the str-filter() function
> will
> be much faster.
>
> For example the same two transformations on a 90000 long string
> resulted in:
>
> str-filter() double-translate()
> ----------- ------------------
> 2.114 11.562
>
>
> Bellow is the text of the DVC variant of str-filter().
>
> str-filterDVC.xsl:
> -----------------
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >
>
> <xsl:template name="str-filter">
> <xsl:param name="pStr"/>
> <xsl:param name="pController" select="/.."/>
> <xsl:param name="pElName" select="'str'"/>
>
> <xsl:if test="not($pController)">
> <xsl:message terminate="yes">[str-filter]Error: pController not
> specified.</xsl:message>
> </xsl:if>
>
> <xsl:element name="{$pElName}">
> <xsl:call-template name="_str-filter">
> <xsl:with-param name="pStr" select="$pStr"/>
> <xsl:with-param name="pController" select="$pController"/>
> </xsl:call-template>
> </xsl:element>
>
> </xsl:template>
>
> <xsl:template name="_str-filter">
> <xsl:param name="pStr" />
> <xsl:param name="pController" select="/.."/>
>
> <xsl:variable name="vLen" select="string-length($pStr)"/>
>
> <xsl:choose>
> <xsl:when test="$vLen = 1">
>
> <xsl:variable name="vHolds">
> <xsl:apply-templates select="$pController">
> <xsl:with-param name="arg1" select="$pStr"/>
> </xsl:apply-templates>
> </xsl:variable>
>
> <xsl:if test="string($vHolds)">
> <xsl:copy-of select="$pStr"/>
> </xsl:if>
> </xsl:when>
> <xsl:when test="$vLen > 1">
> <xsl:variable name="vHalf" select="floor($vLen div 2)"/>
>
> <xsl:call-template name="_str-filter">
> <xsl:with-param name="pStr"
> select="substring($pStr, 1, $vHalf)"/>
> <xsl:with-param name="pController" select="$pController"/>
> </xsl:call-template>
>
> <xsl:call-template name="_str-filter">
> <xsl:with-param name="pStr"
> select="substring($pStr, $vHalf + 1)"/>
> <xsl:with-param name="pController" select="$pController"/>
> </xsl:call-template>
> </xsl:when>
> </xsl:choose>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> I think this is just an example of the potential of useful
> functionality and efficiency, offered by the functional programming
> library FXSL.
>
> Cheers,
> Dimitre Novatchev.
>
>
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Greetings - send holiday greetings for Easter, Passover
> http://greetings.yahoo.com/
>
__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list