Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Christian Stocker's Blog:
Calling PHP function from XSLT vs. native XSLT functions benchmark
Mar 27, 2006 @ 12:55:47

One of the more underused thechnologies to come along these days is XSLT - that powerful langauge to style XML documents in a simple, "more correct" kind of way (seperation of data and layout). Most languages have support for this combination, including PHP - but what's the best way to combine PHP and XSLT? Christian Stocker took a look in this new post on the Bitflux blog.

After Rob's idea from yesterday about using XMLReader within XSLT I was wondering, how much of a slowdown calling PHP functions from XSLT is.

I wrote 4 different XSLT templates, which do a simple substring. One with the xslt function "substring", one with just calling the native PHP function "substr" and one with calling a user-defined function (which is also just calling "substr"). I called this 100 times (with one of those great recursive self-calling xslt-templates) and did call the "transformToXML" function a 100 times for each stylesheet. This means, we called the function 10'000 times for each benchmark run.

His bases the results off of a sample with no function call at all and, but running it through 100 times, came up with results that weren't all that surprising. In order of speed, the ranking (shortest time first) was: no call, xslt only, php native, and php userland. Using the PHP functions from inside of XSLT made the test quite a bit slower, but, as he notes, most users won't be running recursions of 100 each time they run a script.

tagged: XSLT native functions user-defined substring substr XSLT native functions user-defined substring substr

Link:


Trending Topics: