stargeek
PHP news website logo.
home    PHP scripts    articles    seo tools    links    search    contact    shop    realtors


High Speed XML Parsing is Not Intuitive







High Speed XML Parsing is Not Intuitive

High Speed XML Parsing is Not Intuitive 02/11/2004 03:58 AM

For a PHP weblog, there haven't been many PHP articles or links recently. This is because I feel most recent PHP articles I read have nothing fresh to say, repeating material I linked to 2 or 3 years ago. Perhaps I'm getting jaded. So to keep things fresh, here's a new article, mostly original, and hopefully of some interest to everyone!

Last year, Tim Bray, one of the co-authors of the XML spec, mentioned that he used Perl regular expressions to parse XML.

Now here's the dirty secret; most of it is machine-generated XML, and in most cases, I use the perl regexp engine to read and process it.

I was struck by this because I would have thought XPath or SAX would provide better performance as they are APIs tuned specifically for XML.

I decided to do some benchmarks to determine which techniques were better. I also wanted a realistic test, so I benchmarked parsing the RSS feed of this web-site, searching for the contents of all title tags, and returning the contents as an array. The RSS file is from Nov 2003 (yes i did this benchmark that long ago), and is about 20K and has 12 title tags, so the returned array will have 12 title strings.

The techniques used were:

1. Regular expression: preg_match_all('/<title>([^<]*)/',$rss,$titles_arr))

2. Explode('<title>', $rss) then strip the matching </title> tag using strpos() and substr().

3. XPath, using $title_nodes = $ctx->xpath_eval("//title");

4. SAX, wrote an element handler function that matched and processed the title tag.

5. DOM, using $titles = $dom->get_elements_by_tagname('title'). Intuitively, this should have been the slowest, as the whole tree is generated.

Results

Here are the timings for processing the RSS file 1000 times. Faster is better.

            seconds       Relative 
                          to REGEX
REGEX       0.1080          1.00
EXPLODE     0.1696          1.57
DOM         6.3212         58.53
XPATH       8.3417         77.24
SAX        10.0851         93.38

Conclusion

Intutively, I would have thought that XPath would be the fastest as XPath expressions can be compiled and tuned for XML. But the best performance was achieved using regular expressions, which is what Tim is using.

It appears that the DOM, SAX and XPath libraries remain immature (compared to the Perl-compatible regex library) and are not highly optimized. Strangely enough, DOM performance is better than XPath and SAX! Perhaps someone else can explain why.

If anyone is interested, i can post the source.

Test platform: Windows 2000, PHP 4.3.3. I also tested on Linux, PHP 4.3.2, with similar results.




This is a GrokNews Entry: (what is grok?)





Similar Items

High Speed XML Parsing is Not Intuitive

Grok Headline matches for High Speed XML Parsing is Not Intuitive

Kids Give High Marks To High Speed
Internet - Considered Crucial For
Educational Success.


Kids Give High Marks To High Speed
Internet - Considered Crucial For
Educational Success.
08/17/2004 07:45 AM
Hispanicad.com - Tue Aug 17, 09:41 am GMT

NEC Electronics Introduces 3G Mobile
Phone Chip; Enables High-Speed Serial
Data Transmission and Rotating High


NEC Electronics Introduces 3G Mobile
Phone Chip; Enables High-Speed Serial
Data Transmission and Rotating High
07/15/2004 10:14 PM
JCNN Jul 16 2004 0:38AM GMT

National Survey Finds Kids Give High
Marks to High Speed; Internet Considered
Crucial for Educational Success


National Survey Finds Kids Give High
Marks to High Speed; Internet Considered
Crucial for Educational Success
08/13/2004 10:44 AM
Hispanic PR Wire Aug 13 2004 2:17PM GMT

"High Speed Internet"


"High Speed Internet" 09/24/2004 04:07 PM

High-speed hopes for AT&T


High-speed hopes for AT&T 07/23/2004 11:10 AM
The company's slow road back into the residential phone market will be tied to broadband's march across the United States.

MSN TV Broadband: High Speed Web TV


MSN TV Broadband: High Speed Web TV 07/27/2004 01:12 PM

msn_tv_broadband.jpg imageIt's not 1998, I promise, despite this announcement from Microsoft and Thomson to release an updated MSN-branded set-top box for browsing the web and streaming media from other household PCs. To launch in October, the $200 broadband-enabled box will come with a wireless keyboard and remote and will not have much in the way of built-in storage to "prevent vulnerability to virus attacks" (and to keep things cheap). MSN TV (formerly Web TV) has a small, if anachronistically loyal following, but is there really a need for a second generation, even if it does support broadband? Especially if it supports broadband?

The current-generation device is pictured; we'll get you pictures of the new device as soon as we can.

Read - Broadband MSN TV Device Slated [Twice]


KTF Tries Out High-Speed Portable
Internet


KTF Tries Out High-Speed Portable
Internet
09/16/2004 03:37 AM
Yonhap News Sep 16 2004 7:34AM GMT

Handhelds tap in to high-speed delivery


Handhelds tap in to high-speed delivery 06/02/2004 10:52 PM
Sympatico Jun 3 2004 3:37AM GMT

New Outlet for High-Speed Access


New Outlet for High-Speed Access 02/18/2004 07:51 AM
Services offering broadband over power networks are still far from prevalent or profitable. But with advances in transmission capability, along with greater attention from regulators, the technology is gaining momentum. By Joanna Glasner.

High-speed access to Net booming


High-speed access to Net booming 07/08/2004 05:31 PM
globetechnology.com Jul 8 2004 9:48PM GMT

US FCC: High Speed Internet and
television


US FCC: High Speed Internet and
television
09/16/2004 01:04 PM
Digital Lifestyles Sep 16 2004 4:51PM GMT

High Speed Steam Powered Car


High Speed Steam Powered Car 12/28/2004 12:49 PM

Free High-Speed Internet...May Not Be


Free High-Speed Internet...May Not Be 12/24/2004 12:57 PM

Something to look out for when you travel: hotels advertising "Free High-Speed Internet" may be fudging the terms just a little bit.

I stayed in a hotel in New Jersey once that advertised this. I was all excited to get my laptop hooked up and check my email when I discovered what it really meant —

They had some kind of Web TV thing. You got high-speed service to about 15 sites on the television: CNN, the New York Times, and a few others. To get "Free and Unrestricted High-Speed Internet," you had to pay $14.95 a day. And even then, you were still hampered by this crappier-than-WebTV interface that my Web mail refused to work for.

Needless to say, I was a little irritated. Now I never take "Free High-Speed Internet" at face value again. I always ask at the front desk. Not all hotels are this way (this one, in particular, was great), but has anyway else encountered this same problem?


High-Speed DVD Burner Roundup


High-Speed DVD Burner Roundup 05/25/2004 11:59 AM
Are single layer burners still relevant? You bet. With prices dropping below the $100 mark, high-speed, single layer burners are versatile and speedy. We check out the current crop of DVD burners and pick our favorites.

Toronto skyline at high speed


Toronto skyline at high speed 12/06/2003 09:48 AM
This is a breathtaking 24h time-lapse film of the Toronto skyline. The sunrise, in particular, is spectacular. 5.07M B Quicktime Link (Thanks, homerj!)

4.4 M Cdn households have high-speed
internet


4.4 M Cdn households have high-speed
internet
07/08/2004 02:05 PM
CTV.ca Jul 8 2004 6:50PM GMT

High-speed US net 'pirates' sued


High-speed US net 'pirates' sued 04/13/2005 12:04 PM
US record companies and movie studios sue students they say have shared files over a high-speed network.

Cingular's high-speed 3G network


Cingular's high-speed 3G network 05/27/2004 03:20 AM
Engadget May 27 2004 6:07AM GMT

More regions get high speed internet


More regions get high speed internet 11/14/2003 10:21 AM
ONE News Nov 14 2003 9:01AM ET

FCC: High-speed connections up in 2004


FCC: High-speed connections up in 2004 01/04/2005 05:25 PM
Homes and businesses with speedy connections increased from 28.2 million to 32.5 million lines during six-month period ending in June 2004, report says.

Other nations zip by USA in high-speed
Net race


Other nations zip by USA in high-speed
Net race
01/22/2004 02:10 AM

America: Still the High-Speed Laggard


America: Still the High-Speed Laggard 04/08/2005 06:18 PM
“Compared to South Korea, Japan, even Canada, broadband adoption in the U.S. is falling behind. For 20% of Americans, it’s not even an option In the early 1990s, Taylor Reynolds spent time as an exchange student in South Korea — a good deal of it hunting for a computer on which to write his term papers. “I finally found someone whose sister worked in a preschool, and it had a computer,” he remembers. “I had…

Direct and Related Links for 'America: Still the High-Speed Laggard'


US high-speed connections surge


US high-speed connections surge 12/24/2003 07:40 AM
ZDNet UK Dec 24 2003 6:42AM ET

Bluetooth Kicking into High Speed


Bluetooth Kicking into High Speed 06/09/2004 03:36 PM
BrightHand Jun 9 2004 7:20PM GMT

2 in 5 Web Users Have High-Speed at Home
(AP)


2 in 5 Web Users Have High-Speed at Home
(AP)
04/19/2004 06:58 AM
AP - Two in five Internet users in the United States now have high-speed access at home as telephone companies slash prices to better compete with cable broadband services, a study says.

Update: Mobile High Speed 3G 4.10


Update: Mobile High Speed 3G 4.10 12/17/2004 06:26 PM
The 3G, EDGE, and GPRS mobile phone connection manager adds support for recently-released mobile phones from Nokia, Motorola, and SonyEricsson.

2GB Memory Stick PRO Duo (High-Speed)


2GB Memory Stick PRO Duo (High-Speed) 03/30/2005 03:59 AM

2gb_memorystick.jpg imageSony is finally getting around to releasing their 2GB Memory Stick Pro Duo (High-Speed) cards. They announced these things back in September of 2004, and have kicked the release date back twice. The "(High-Speed)" in the name indicates the cards have a transfer rate of 80Mbps (10MB/sec), which is far more than you'll ever need for anything practical. Sony really needs to do something about this Memory Stick naming scheme, because it's getting to be like Street Fighter games. I needn't remind you this stick is PSP compatible.

Press Release [Sony]


High-speed Net prices plunge


High-speed Net prices plunge 11/14/2003 02:22 AM
USA Today Nov 14 2003 1:34AM ET

High-Speed Love Connection


High-Speed Love Connection 06/24/2004 04:46 AM
Have an Internet hookup? Sexual gratification is a mouseclick away, thanks to remote-control, scriptable sex toys. By Xeni Jardin.

Update: Mobile High Speed 3.2


Update: Mobile High Speed 3.2 02/17/2004 11:51 AM
The GPRS/EDGE and HSCSD/GSM mobile phone connection manager adds support for the SonyEricsson GC82 EDGE/GPRS and Sierra Wireless AC750, an improved interface, and other changes.

2 in 5 Web Users Have High-Speed at Home


2 in 5 Web Users Have High-Speed at Home 04/19/2004 09:37 AM
AP via Daily Press Apr 19 2004 1:57PM GMT

SBC to offer high-speed Internet for $15


SBC to offer high-speed Internet for $15 06/06/2005 12:07 AM
Seattletimes.nwsource.com - Wed Jun 1, 09:39 pm GMT

High-speed internet lines increase in
U.S.


High-speed internet lines increase in
U.S.
06/10/2004 01:10 PM

AT&T plugs into power lines for
high-speed Net


AT&T plugs into power lines for
high-speed Net
07/14/2004 06:57 PM
AT&T teams up with power company to test how broadband can be sent over power lines, an emerging alternative to cable and DSL.

Other nations zip by USA in high-speed
Net race (USATODAY.com)


Other nations zip by USA in high-speed
Net race (USATODAY.com)
01/19/2004 08:24 AM
USATODAY.com - LaBelle Management fights a poky dial-up Internet connection every morning to see how 13 restaurants did the day before.

High-Speed Internet Lines Increase in
U.S


High-Speed Internet Lines Increase in
U.S
06/10/2004 01:03 PM
AP via Los Angeles Times Jun 10 2004 5:36PM GMT

High-Speed Internet Lines Increase in
U.S. (AP)


High-Speed Internet Lines Increase in
U.S. (AP)
06/10/2004 08:50 PM
AP - The number of high-speed Internet lines in the United States increased 42 percent last year, and service now is available in all but 7 percent of the nation's ZIP codes.

AT&T Wireless launches high-speed
service


AT&T Wireless launches high-speed
service
07/20/2004 11:18 AM
Subscribers in four U.S. cities now can dial up broadband speed on their cell phones.

Music Biz Sues High-Speed Traders


Music Biz Sues High-Speed Traders 04/13/2005 05:46 AM
The blazing-fast Internet2 research network has been hijacked for illegal file sharing, according to the entertainment industry. The RIAA and MPAA launch another round of lawsuits against hundreds of students. By Katie Dean.
Grok Description matches for High Speed XML Parsing is Not Intuitive
GrokA matches for High Speed XML Parsing is Not Intuitive

High Speed XML Parsing is Not Intuitive

The following phrases have been identified by the grok system as matching this entry:

















Also check out:


Grok

Ipod Porn on the
Rise

Brief Abstract of
Wikipedia's
Mesothelioma Cancer
page

Get first aid
instructions in your
cell phone

IE is crap
JSPWiki gains
podcasting support

CC at SXSW
insuperable:
Dictionary.com Word
of the Day

Talks on Unwinding
Vodafone-Verizon
Venture Intensify
(Dow Jones)

Senators Try to
Break Impasse on
Internet Taxes
(washingtonpost.com)

Porn site
Whitehouse.com up
for sale (Reuters)

animated dreams
Israeli Troops Kill
Nine Palestinians in
Gaza (Reuters)

Nets Top Pistons for
9th Consecutive Win
(AP)

Bird Flu Prompts
Del. to Kill
Chickens (AP)

DVDFILE.COM: Disc
News

Bush at Sea - Does
this war president
have any idea what
he's talking about?
By Fred Kaplan

Techdirt:Compare And
Contrast Blogs And
Reuters On Joe
Trippi's Speech

SignOnSanDiego.com
> News >
Nation --
Conservative U.S.
anchor now skeptical
about Bush

Linux gets small:
LNX-BBC and
DamnSmall Linux

Oscar head angry at
TV show delay

Smoking outside
'harms children'

True number of poor
'disguised'

Appeal over sex
offender murder

Church set to
reignite gay debate

Taiwan-Brazil
custody battle ends

Cricket: Warne makes
return

Football: Fans
target Gold Cup

Shareholder joy as
BSkyB soars

Cockle picker's last
call to wife

Dilbert for 11 Feb
2004

Red alert for
Microsoft

'Get-Set-Go' to win
with Microsoft
hardware

Microsoft issue
security warning

Justice Department
staff opposes Oracle
bid

Programmer sets up
mask for
file-sharers

Korea Tops Internet
Usage Rate

Nokia grabs Psion's
Symbian stake

Super Bowl
advertisers' Web
sites get super
boost

Microsoft Warns of
'Critical' Security
Vulnerability in
Windows

Senators Try to
Break Impasse on
Internet Taxes: New
Bill Would Ban
Levies on Service
Provider Fees Only

Pictures of
Mountains and
Clouds...

Jail separation
under fire

CipherDisk 1.5
offers AES
encryption

TiVo Doesn't Violate
Patent On Pausing TV

New Service Designed
To Hide IP Addresses
Of File Sharers

Add Your Library to
MyYahoo!

Sun to discuss
next-generation
'Rock' chip

Spike Lee's "Secret
Agent Man" SPOT
video

XMLHTTP call fails
for URLs with
embedded user
credentials

The Best For
Broadband: AOL vs.
MSN

NFL, TV Execs to
Testify on Capitol
Hill (AP)

Israeli Troops Kill
Four Palestinians
(AP)

Motorola announces 3
new PTT phones

Wookiee! 'Star Wars'
Trilogy Set for
Sept. DVD Release
(washingtonpost.com)

Microsoft Warns
Software Users of
'Critical' Flaw

what is grok?