473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

XSLT speed comparisons

Hi, I'm from an ASP.NET background an am considering making the switch
to Python. I decided to develop my next project in tandem to test the
waters and everything is working well, loving the language, etc.

What I've got is:
two websites, one in ASP.NET v2 and one in Python 2.5 (using 4suite for
XML/XSLT)
both on the same box (Windows Server 2003)
both using the same XML, XSLT, CSS

The problem is, the Python version is (at a guess) about three times
slower than the ASP one. I'm very new to the language and it's likely
that I'm doing something wrong here:

from os import environ
from Ft.Lib.Uri import OsPathToUri
from Ft.Xml import InputSource
from Ft.Xml.Xslt import Processor

def buildPage():
try:
xsluri = OsPathToUri('xsl/plainpage.xsl')
xmluri = OsPathToUri('website.xml')

xsl = InputSource.DefaultFactory.fromUri(xsluri)
xml = InputSource.DefaultFactory.fromUri(xmluri)

proc = Processor.Processor()
proc.appendStylesheet(xsl)

params = {"url":environ['QUERY_STRING'].split("=")[1]}
for i, v in enumerate(environ['QUERY_STRING'].split("/")[1:]):
params["selected_section%s" % (i + 1)] = "/" + v

return proc.run(xml, topLevelParams=params)
except:
return "Error blah blah"

print "Content-Type: text/html\n\n"
print buildPage()

You can compare the development sites here:
asp: http://consultum.pointy.co.nz/about/team
python: http://python.pointy.co.nz/about/team

Cheers!

Sep 27 '06 #1
21 2500
Damian wrote:
two websites, one in ASP.NET v2 and one in Python 2.5 (using 4suite for
XML/XSLT)
both on the same box (Windows Server 2003)
both using the same XML, XSLT, CSS

The problem is, the Python version is (at a guess) about three times
slower than the ASP one.
It could just be that 4suite is slower than MSXML. If so, you can use
MSXML in Python if you want. You'll need to install the Python for
Windows extensions. Something like this:

from os import environ
import win32com.client

def buildPage():
xsluri = 'xsl/plainpage.xsl'
xmluri = 'website.xml'

xsl = win32com.client.Dispatch("Msxml2.FreeThreadedDOMDo cument.4.0")
xml = win32com.client.Dispatch("Msxml2.DOMDocument.4.0")
xsl.load(xsluri)
xml.load(xmluri)

xslt = win32com.client.Dispatch("Msxml2.XSLTemplate.4.0")
xslt.stylesheet = xsl
proc = xslt.createProcessor()
proc.input = xml

params = {"url":environ['QUERY_STRING'].split("=")[1]}
for i, v in enumerate(environ['QUERY_STRING'].split("/")[1:]):
params["selected_section%s" % (i + 1)] = "/" + v

for param, value in params.items():
proc.addParameter(param, value)
proc.transform()
return proc.output

print "Content-Type: text/html\n\n"
print buildPage()
Ross Ridge

Sep 27 '06 #2
Ross Ridge wrote:
It could just be that 4suite is slower than MSXML. If so, you can use
MSXML in Python if you want. You'll need to install the Python for
Windows extensions. Something like this:
Thanks for that Ross. That would make sense, I'd read somewhere that
the 4suite code was a little slower but wanted to be sure it wasn't
just something I'd done wrong.

I've experimented with the code you supplied and after installing the
necessaries have run into a brick wall with a series of errors.

The errors can be seen at http://python.pointy.co.nz/test (I'm leaving
the existing, slower version running at the moment for the rest of the
site).

I've got to get back on with some work but will look further into this
tonight.

Thanks for your help! I really appreciate it.

Sep 27 '06 #3
Damian wrote:
The errors can be seen at http://python.pointy.co.nz/test (I'm leaving
the existing, slower version running at the moment for the rest of the
site).
Hmm... it seems that you don't have MSXML 4.0 installed on your
machine. I missed the fact that you're using ASP.NET, so your ASP code
probably is probably using the .NET XML implementation instead of
MSXML. In that case, another alternative might be to use IronPython
and just translate your ASP script into Python.

Ross Ridge

Sep 28 '06 #4
Ross Ridge wrote:
Hmm... it seems that you don't have MSXML 4.0 installed on your
machine. I missed the fact that you're using ASP.NET, so your ASP code
probably is probably using the .NET XML implementation instead of
MSXML. In that case, another alternative might be to use IronPython
and just translate your ASP script into Python.

Ross Ridge
Sorted!

I installed msxml4 and then struggled for an hour or so with an
encoding error (UnicodeEncodeError: 'ascii' codec.... etc) which was
fixed by altering your code from:

return proc.output --return proc.output.encode('utf-8')

The performance of MSXML over 4suite is substantial.
4suite: http://python.pointy.co.nz/test = 2.5s
MSXML: http://python.pointy.co.nz/test_msxml = 1.1s

I'd like to eventually break all ties with MS at some stage. It'll be
interesting to test this performance on a Linux server.

Thank you for your help Ross.

Sep 28 '06 #5
Ross Ridge wrote:

>The problem is, the Python version is (at a guess) about three times
slower than the ASP one.

It could just be that 4suite is slower than MSXML. If so, you can use
MSXML in Python if you want.
or use lxml:

http://codespeak.net/lxml/

(does anyone have any lxml/libxslt vs. msxml benchmarks, btw?)

</F>

Sep 28 '06 #6
Ross Ridge wrote:
Hmm... it seems that you don't have MSXML 4.0 installed on your
machine. I missed the fact that you're using ASP.NET, so your ASP code
probably is probably using the .NET XML implementation instead of
MSXML. In that case, another alternative might be to use IronPython
and just translate your ASP script into Python.
Sorted!

I installed msxml4 and then struggled for an hour or so with an
encoding error (UnicodeEncodeError: 'ascii' codec.... etc) which was
fixed by altering your code from:

return proc.output --return proc.output.encode('utf-8')

The performance of MSXML over 4suite is substantial.
4suite: http://python.pointy.co.nz/test = 2.5s
MSXML: http://python.pointy.co.nz/test_msxml = 1.1s

I'd like to eventually break all ties with MS at some stage. It'll be
interesting to test this performance on a Linux server.

Thank you for your help.

Damian

Sep 28 '06 #7
Sorted!

I installed msxml4 and then struggled for an hour or so with an
encoding error (UnicodeEncodeError: 'ascii' codec.... etc) which was
fixed by altering your code from:

return proc.output --return proc.output.encode('utf-8')

The performance of MSXML over 4suite is substantial.
4suite: http://python.pointy.co.nz/test = 2.5s
MSXML: http://python.pointy.co.nz/test_msxml = 1.1s

I'd like to eventually break all ties with MS at some stage. It'll be
interesting to test this performance on a Linux server.

Thank you for your help.

Damian

Sep 28 '06 #8
Damian wrote:
Hi, I'm from an ASP.NET background an am considering making the switch
to Python. I decided to develop my next project in tandem to test the
waters and everything is working well, loving the language, etc.

What I've got is:
two websites, one in ASP.NET v2 and one in Python 2.5 (using 4suite for
XML/XSLT)
both on the same box (Windows Server 2003)
both using the same XML, XSLT, CSS

The problem is, the Python version is (at a guess) about three times
slower than the ASP one. I'm very new to the language and it's likely
that I'm doing something wrong here:

from os import environ
from Ft.Lib.Uri import OsPathToUri
from Ft.Xml import InputSource
from Ft.Xml.Xslt import Processor

def buildPage():
try:
xsluri = OsPathToUri('xsl/plainpage.xsl')
xmluri = OsPathToUri('website.xml')

xsl = InputSource.DefaultFactory.fromUri(xsluri)
xml = InputSource.DefaultFactory.fromUri(xmluri)

proc = Processor.Processor()
proc.appendStylesheet(xsl)

params = {"url":environ['QUERY_STRING'].split("=")[1]}
for i, v in enumerate(environ['QUERY_STRING'].split("/")[1:]):
params["selected_section%s" % (i + 1)] = "/" + v

return proc.run(xml, topLevelParams=params)
except:
return "Error blah blah"

print "Content-Type: text/html\n\n"
print buildPage()

You can compare the development sites here:
asp: http://consultum.pointy.co.nz/about/team
python: http://python.pointy.co.nz/about/team

Cheers!
For max speed you might want to try pyrxp:

http://www.reportlab.org/pyrxp.html

-Larry
Sep 28 '06 #9
Microsoft has put a lot of effort into their XML libraries as they are
(or will be) the foundation of most of their software suites. I think
you'll be hard pressed to find a library that exceeds it in both
breadth of functionality and performance.

Istvan

Sep 28 '06 #10
Larry Bates wrote:
Damian wrote:
[...]
What I've got is:
two websites, one in ASP.NET v2 and one in Python 2.5 (using 4suite for
XML/XSLT)
both on the same box (Windows Server 2003)
both using the same XML, XSLT, CSS

The problem is, the Python version is (at a guess) about three times
slower than the ASP one. I'm very new to the language and it's likely
that I'm doing something wrong here:
[...]
For max speed you might want to try pyrxp:

http://www.reportlab.org/pyrxp.html
Except that pyrxp, to the best of my knowledge, is an XML parser and
doesn't support XSLT, which is a requirement for Damian.

Regards,
Jan
Sep 28 '06 #11
Jan Dries wrote:
Larry Bates wrote:
>Damian wrote:
[...]
What I've got is:
two websites, one in ASP.NET v2 and one in Python 2.5 (using 4suite for
XML/XSLT)
both on the same box (Windows Server 2003)
both using the same XML, XSLT, CSS

The problem is, the Python version is (at a guess) about three times
slower than the ASP one. I'm very new to the language and it's likely
that I'm doing something wrong here:
[...]
>
For max speed you might want to try pyrxp:

http://www.reportlab.org/pyrxp.html

Except that pyrxp, to the best of my knowledge, is an XML parser and
doesn't support XSLT, which is a requirement for Damian.

Regards,
Jan
Oops, I should have read the OPs post closer.

-Larry
Sep 28 '06 #12
Jan Dries wrote:
>For max speed you might want to try pyrxp:

http://www.reportlab.org/pyrxp.html

Except that pyrxp, to the best of my knowledge, is an XML parser and
doesn't support XSLT, which is a requirement for Damian.
and last time I checked, both cElementTree and libxml2 (lxml.etree) was
faster, so the "max speed" claim isn't that accurate either...

</F>

Sep 28 '06 #13
Jan Dries wrote:
Larry Bates wrote:
>Damian wrote:
[...]
What I've got is:
two websites, one in ASP.NET v2 and one in Python 2.5 (using 4suite for
XML/XSLT)
both on the same box (Windows Server 2003)
both using the same XML, XSLT, CSS

The problem is, the Python version is (at a guess) about three times
slower than the ASP one. I'm very new to the language and it's likely
that I'm doing something wrong here:
[...]
>
For max speed you might want to try pyrxp:

http://www.reportlab.org/pyrxp.html

Except that pyrxp, to the best of my knowledge, is an XML parser and
doesn't support XSLT, which is a requirement for Damian.

Regards,
Jan
Oops, I should have read the OPs post closer.

-Larry

Sep 28 '06 #14
Sorry about the multiple posts folks. I suspect it was the "FasterFox"
FireFox extension I installed yesterday tricking me.

I had a brief look at libxml(?) on my Ubuntu machine but haven't run it
on the server.

I'll look into pyrxp Larry.

I have to say I'm struggling a little with the discoverability and
documentation side of things with Python. I realise that
discoverability is purported to be one of its strong sides but coming
from the Visual Studio IDE where Intellisense looks after everything as
you are typing and you can see exactly what methods are available to
what class and what variables are required and why what I've seen so
far is not that flash.

I've installed Eclipse with Pydev (very impressive) on my Linux box and
am using IDLE on Windows and it could just be my lack of familiarity
that is letting me down. Any other IDE recommendations?

I'd be keen to test pyrxp and libxslt but may need help with the code -
I spent literally hours yesterday trying to make a 20-line bit of code
work. To make things worse I started with 4suite in Ubuntu and it
refused to work with an error about not being able to find default.cat
or something. Googled for hours with no luck.

That said, I really want to make the switch and so far Python looks to
be the best choice.

Cheers
Damian

Sep 28 '06 #15
Ahhhh, thanks for that, I've been searching the documentation and it
only briefly mentions XSLT but it sounds like a half-arsed attempt.

Sep 28 '06 #16
Damian wrote:
Hi, I'm from an ASP.NET background an am considering making the switch
to Python. I decided to develop my next project in tandem to test the
waters and everything is working well, loving the language, etc.

What I've got is:
two websites, one in ASP.NET v2 and one in Python 2.5 (using 4suite for
XML/XSLT)
both on the same box (Windows Server 2003)
both using the same XML, XSLT, CSS

The problem is, the Python version is (at a guess) about three times
slower than the ASP one. I'm very new to the language and it's likely
The ASP one being MSXML, right? In that case that result doesn't
surprise me.
that I'm doing something wrong here:
Now wrong, but we can definitely simplify your API
from os import environ
from Ft.Lib.Uri import OsPathToUri
from Ft.Xml import InputSource
from Ft.Xml.Xslt import Processor

def buildPage():
try:
xsluri = OsPathToUri('xsl/plainpage.xsl')
xmluri = OsPathToUri('website.xml')

xsl = InputSource.DefaultFactory.fromUri(xsluri)
xml = InputSource.DefaultFactory.fromUri(xmluri)

proc = Processor.Processor()
proc.appendStylesheet(xsl)

params = {"url":environ['QUERY_STRING'].split("=")[1]}
for i, v in enumerate(environ['QUERY_STRING'].split("/")[1:]):
params["selected_section%s" % (i + 1)] = "/" + v

return proc.run(xml, topLevelParams=params)
except:
return "Error blah blah"

print "Content-Type: text/html\n\n"
print buildPage()
This should work:

from os import environ
from Ft.Xml.Xslt import Transform

def buildPage():
try:
params = {"url":environ['QUERY_STRING'].split("=")[1]}
for i, v in enumerate(environ['QUERY_STRING'].split("/")[1:]):
params["selected_section%s" % (i + 1)] = "/" + v

return Transform('website.xml', 'xsl/plainpage.xsl',
topLevelParams=params)
except:
return "Error blah blah"

print "Content-Type: text/html\n\n"
print buildPage()

-- % --

For what it's worth I just developed, and switched to WSGI middleware
that only does the transform on the server side if the client doesn't
understand XSLT. It's called applyxslt and is part of wsgi.xml [1].
That reduces server load, and with caching (via Myghty), there's really
no issue for me. For more on WSGI middleware see [2].

[1] http://uche.ogbuji.net/tech/4suite/wsgixml/
[2] http://www.ibm.com/developerworks/library/wa-wsgi/

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

Sep 29 '06 #17
Ross Ridge wrote:
Damian wrote:
It could just be that 4suite is slower than MSXML. If so, you can use
MSXML in Python if you want. You'll need to install the Python for
Windows extensions. Something like this:

from os import environ
import win32com.client

def buildPage():
[SNIP]

Added to:

http://uche.ogbuji.net/tech/akara/no...01/python-xslt

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

Sep 29 '06 #18
uc*********@gmail.com wrote:
For what it's worth I just developed, and switched to WSGI middleware
that only does the transform on the server side if the client doesn't
understand XSLT. It's called applyxslt and is part of wsgi.xml [1].
That reduces server load, and with caching (via Myghty), there's really
no issue for me. For more on WSGI middleware see [2].

[1] http://uche.ogbuji.net/tech/4suite/wsgixml/
[2] http://www.ibm.com/developerworks/library/wa-wsgi/
I just wanted to clarify that not only does the applyxslt middleware
approach reduce server load, but in the case of clients running IE6 or
IE7, the XSLT *does* end up being executed in MSXML after all: MSXML on
the client's browser, rather than on the server. In the case of
Mozilla it's Transformiix, which is between MSXML and 4Suite in
performance. Not sure what's the XSLT processor in the case of Safari
(only the most recent versions of Safari). But regardless, with that
coverage you can write apps using XSLT, support the entire spectrum of
browsers (and mobile apps, spiders, etc.) and yet rarely ever require
XSLT applied on the server side.

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/
Sep 29 '06 #19
If your using python 2.4.3 or essentially any of the 2.3, 2.4 series,
i'd test out PyScripter as an IDE, it's one of the best that I've used.
Unfortunately, they have yet to fully accomedate 2.5 code (you can
still write 2.5 code with almost no problems, but you won't be able to
use a 2.5 interactive interpeter).
Damian wrote:
Sorry about the multiple posts folks. I suspect it was the "FasterFox"
FireFox extension I installed yesterday tricking me.

I had a brief look at libxml(?) on my Ubuntu machine but haven't run it
on the server.

I'll look into pyrxp Larry.

I have to say I'm struggling a little with the discoverability and
documentation side of things with Python. I realise that
discoverability is purported to be one of its strong sides but coming
from the Visual Studio IDE where Intellisense looks after everything as
you are typing and you can see exactly what methods are available to
what class and what variables are required and why what I've seen so
far is not that flash.

I've installed Eclipse with Pydev (very impressive) on my Linux box and
am using IDLE on Windows and it could just be my lack of familiarity
that is letting me down. Any other IDE recommendations?

I'd be keen to test pyrxp and libxslt but may need help with the code -
I spent literally hours yesterday trying to make a 20-line bit of code
work. To make things worse I started with 4suite in Ubuntu and it
refused to work with an error about not being able to find default.cat
or something. Googled for hours with no luck.

That said, I really want to make the switch and so far Python looks to
be the best choice.

Cheers
Damian
Sep 29 '06 #20
If your using python 2.4.3 or essentially any of the 2.3, 2.4 series,
i'd test out PyScripter as an IDE, it's one of the best that I've used.
Unfortunately, they have yet to fully accomedate 2.5 code (you can
still write 2.5 code with almost no problems, but you won't be able to
use a 2.5 interactive interpeter).

Good Luck
Jordan

Damian wrote:
Sorry about the multiple posts folks. I suspect it was the "FasterFox"
FireFox extension I installed yesterday tricking me.

I had a brief look at libxml(?) on my Ubuntu machine but haven't run it
on the server.

I'll look into pyrxp Larry.

I have to say I'm struggling a little with the discoverability and
documentation side of things with Python. I realise that
discoverability is purported to be one of its strong sides but coming
from the Visual Studio IDE where Intellisense looks after everything as
you are typing and you can see exactly what methods are available to
what class and what variables are required and why what I've seen so
far is not that flash.

I've installed Eclipse with Pydev (very impressive) on my Linux box and
am using IDLE on Windows and it could just be my lack of familiarity
that is letting me down. Any other IDE recommendations?

I'd be keen to test pyrxp and libxslt but may need help with the code -
I spent literally hours yesterday trying to make a 20-line bit of code
work. To make things worse I started with 4suite in Ubuntu and it
refused to work with an error about not being able to find default.cat
or something. Googled for hours with no luck.

That said, I really want to make the switch and so far Python looks to
be the best choice.

Cheers
Damian
Sep 29 '06 #21

Jordan wrote:
If your using python 2.4.3 or essentially any of the 2.3, 2.4 series,
i'd test out PyScripter as an IDE, it's one of the best that I've used.
Unfortunately, they have yet to fully accomedate 2.5 code (you can
still write 2.5 code with almost no problems, but you won't be able to
use a 2.5 interactive interpeter).
An unofficial update supporting Python 2.5 is available at
pyscripter.googlepages.com and an offical release is coming real soon.

Oct 2 '06 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: EP | last post by:
On questions of the suitability of Python for CGI, embedded apps, etc., execution speed comes to mind. I previously read some comparisons which did not show Python in a good light in this regard:...
2
by: dado0583 | last post by:
Hi, I'm currently writing an XSLT Editor tool as part of a university project. I would like to know what those of you that use XSLT look for in an XSLT editor. Currently, the main features will...
3
by: Jack Fox | last post by:
I've never had the need to work with XML, but I believe I now have an appropriate application. I have time-series data in objects organized as a tree that I want an ASP.NET program to write out to...
4
by: Anders Borum | last post by:
Hello! With XSLT 2.0 in the pipeline at the W3 consortium, I'm wondering if Microsoft is planning to support it with the next release of the .NET framework? It sure looks like a promising set of...
5
by: crazydiode | last post by:
HI All, I am new to XSLT. I am trying to use xslt with xml in my java code. I am basically trying to replace one node of the original xml with my own node. I defined the xslt as follows: ...
8
by: markww | last post by:
Hi, This is a continuation of a dead post. I need to make a pixel map where I can store pixel data for multiple images. Multiple windows in my app may render the same image, so I want to keep...
1
by: =?Utf-8?B?R2xlbm4gR29tZXo=?= | last post by:
Does Office Excel 2000 support XSLT transformation of data from XML cause am having problem when the attachment is opened in the client side if the Excels version is in Office 2000 and also its...
1
by: mk | last post by:
Out of curiosity I decided to make some speed comparisons of the same algorithm in Python and C++. Moving slices of lists of strings around seemed like a good test case. Python code: def...
0
by: Rajanikanth Jammalamadaka | last post by:
Try using a list instead of a vector for the C++ version. Raj On Tue, Jul 8, 2008 at 3:06 PM, mk <mrkafk@gmail.comwrote: -- "For him who has conquered the mind, the mind is the best of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.