Python2.6 XML reading
I want to migrate my system from Active Python 2.4 to Python 2.6.5. However I face some problem in parsing XML files. The I/O is very slow.
My sample xml file
<config><dicts><dictName>EnvDict</dictName><dictElems><key>AppServerIP</key> <value>localhost</value><key>DBServerIP</key> <value>localhost</value><key>DBServerName</key> <value>DB1</value></dictElems></dicts></config>
My log shows this xml parsing took 25s.
My system is structure as below
Publisher-Subr is used to redirect request to different modules
ClntMgrFact is attached to PubSubr and listen to pre-defined ports. It will spawn a new process for login from client.
ClntMgr(process) is spawned by ClntMgrFact and also attached to PubSubr. ClntMgr will generate a ClntWor开发者_JAVA百科ker(thread) to process workflow.
ClntWorker need to read some static XML file from local. But the parsing is extremely slow. My XML file is around 500 - 700k.
Any one can help on this without changing the system structure? Thanks in advance.
I'm very perplexed...:
$ py26 -mtimeit -s'import rex' 'rex.t()'
10000 loops, best of 3: 103 usec per loop
100 microseconds seems more reasonable than 25 seconds to read in, and parse, such a small XML file as you're giving (even on the old laptop I'm using for the timing!) -- but how to explain the fact that my parsing is being 250,000 times faster than yours?!
This is rex.py
, btw...:
import xml.etree.cElementTree as et
def t(fn='static.xml'):
return et.parse(fn)
and static.xml
is the file where I wrote your XML example (223 characters).
So what's your platform, OS, Python version, chosen XML parser, etc...? I'm on a macbook pro laptop, OSX 10.5.8, 2.4 GHz Intel Core Duo, 667 MHz DDR2 RAM -- as I said, a pretty old machine indeed! -- with Python 2.6.4 straight from python.org.
精彩评论