How do I time my XSLT execution times to millisecond accuracy?

久未见 提交于 2019-12-11 02:54:37

问题


I have an XSLT (running under Sitecore) that I'd like to benchmark.

For example:

<xsl:variable name="start_ms" select="TIME IN MILLIS" />

Do something

<xsl:variable name="end_ms" select="TIME IN MILLIS" />
<xsl:variable name="total_ms" select="$end_ms - $start_ms" />

Do something else

Unfortunately I can't manage to get the time to milliseconds accuracy.

If I include xmlns:date="http://exslt.org/dates-and-times" I get date:dateTime(), but that only goes to seconds accuracy.

Similarly, sc:formatdate(sc:isoNow(),'ss.ffff') also only goes to seconds accuracy.

The Sitecore "debug page" functionality will tell me how long it takes to run the entire XSLT, but it wont let me benchmark individual components of the XSLT.

Is there any way to do this?


回答1:


The Sitecore "debug page" functionality will tell me how long it takes to run the entire XSLT, but it wont let me benchmark individual components of the XSLT.

Is there any way to do this?

This strongly depends on the XSLT processor you are using, and the results generally maynot be trustworthy.

Even if you write your own extension functions and call them from the XSLT code (which seems to be the only way to achieve the desired timing precision), nothing guarantees that the extension function would be called when expected. or that it won't be called more than once when one call is expected. This is because we cannot predict and anticipate the decision of the optimizer used by a particular XSLT processor.

Some XSLT processors implement lazy evaluation -- an expression isn't evaluated unless it has become absolutely necessary for producing the result. Such a processor would execute the call to the timing extension function only when its result is used -- and that may be at the end of the measured processing -- so in this case any measured processing would be "instantaneous".




回答2:


if you are trying to identify a processing bottleneck, you can move the separate components one by one into a new XSLT, taking millisecond benchmarks at each step using the debug tool.



来源:https://stackoverflow.com/questions/8783696/how-do-i-time-my-xslt-execution-times-to-millisecond-accuracy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!