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

Re: Here's how to benchmark your XSLT program's execut

Subject: Re: Here's how to benchmark your XSLT program's execution time
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 7 Nov 2014 05:44:44 -0000
Re:  Here's how to benchmark your XSLT program's execut
Here is one approach. The extension function:

  my:getTime(bookmark as xs:int) as item()+

produces a sequence of 2 items: the first item is the time, the second
item is the empty string.

Then we'll typically have have:

< xsl:variable name="vTime1" select ="my:getTime(1)"/>

< xsl:value-of select="$vTime1[2]"/>


In a similar way, a computation that can be expressed as a call to the
function fold-left(), can produce as part of the intermediate result
the time received from an extension function. fold-left() is eager and
will typically be optimized as a
loop, because it is tail-recursive. This means that the intermediate
value *has* to be evaluated before the tail-call to fold-left(),
because the outer function seizes to exist as the call is made.

In this way we'll have recorded the time at each call and we'll be
passing this recorded times as part of the parameter to the tail-call
to fold-left().

Of course, all statements about the unpredictability of the moment of
calling the extension function *are* true, but if someone is motivated
to try the above, I would be interested to know the results :)

I should say that I have never needed to use such tricks. Whenever I
have had to perform timing of transformations, I have relied on the
implementation of the particular XSLT processor to show the elapsed
time. When using Saxon, AFAIR this is the "-t" command-line option,
and it is more reliable when combined with "repeat:N".

An even simpler trick, known for ages, is configuring the DOS command
prompt to show the time when it is displayed. Doing so, and promptly
repeating a command-line invocation of a transformation could be used
to get a relatively precise start times -- the end times are quite OK.

Cheers,
Dimitre

On Thu, Nov 6, 2014 at 6:49 AM, Michael Kay mike@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> If this is working, then it's only by chance.
>
> Order of evaluation is undefined in XSLT, and there is no guarantee that $start is evaluated before the apply-templates call is evaluated.
>
> I think this only works in Saxon because the optimizer treats calls on extension functions as suspicious, and tries to avoid over-optimizing them because of potential side-effects.
>
> Michael Kay
> Saxonica
> mike@xxxxxxxxxxxx
> +44 (0) 118 946 5893
>
>
>
>
> On 6 Nov 2014, at 10:20, Costello, Roger L. costello@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> Hi Folks,
>>
>> So, you've got an XSLT program that is taking a long time to execute. You want to find out what part of the program is taking so much time.  You need to insert some start/stop timers into your XSLT. Here's how to do it:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>                xmlns:date="java:java.util.Date"
>>                version="2.0">
>>
>>    <xsl:output method="text" />
>>    <xsl:output name="text-format" method="text"/>
>>
>>    <xsl:template match="/">
>>        <!-- Start a timer -->
>>        <xsl:variable name="start" select="date:getTime(date:new())" />
>>
>>        <!-- Do your XSLT processing -->
>>        <xsl:apply-templates />
>>
>>        <!-- End the timer -->
>>        <xsl:variable name="end" select="date:getTime(date:new())" />
>>
>>        <!-- Log the benchmarking results to a file, time-info.txt -->
>>        <xsl:result-document href="time-info.txt" format="text-format">
>>            start: <xsl:value-of select="$start" />
>>            end: <xsl:value-of select="$end" />
>>            diff: <xsl:value-of select="$end - $start" />
>>        </xsl:result-document>
>>
>>    </xsl:template>
>>
>>    <xsl:template match="*">
>>        <!-- Do something -->
>>        <xsl:text>Hello World </xsl:text>
>>        <xsl:value-of select="current-dateTime()" />
>>    </xsl:template>
>>
>> </xsl:stylesheet>
>>
> 



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

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.