By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,719 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,719 IT Pros & Developers. It's quick & easy.

Performance inquiry

P: n/a
Imagine three options:

a) There is an XML file. A PHP5 script loads it and puts it into a DOM
document object. Then, given an input string, a function looks via XPath
for a node with that name (or possibly value of an attribute) and returns
the node's content.

b) There is a text file containing a serialized array. PHP script opens it
and deserializes the array into a variable; then, given an input string,
looks for an array element with the same key and returns the element's
value.

c) There is a PHP file containing just a definition for an array. PHP
script includes it and, given an input string, looks for an array element
with the same key and returns the element's value.

Does anyone have any idea which option would be the fastest, and which the
slowest of the three?

Thanks,

Berislav
Jul 17 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
As you are clever enough to come up with that question why can't you write
the code to test each option yourself?

--
Tony Marston

http://www.tonymarston.net

"Berislav Lopac" <be************@dimedia.hr> wrote in message
news:k9****************************@40tude.net...
Imagine three options:

a) There is an XML file. A PHP5 script loads it and puts it into a DOM
document object. Then, given an input string, a function looks via XPath
for a node with that name (or possibly value of an attribute) and returns
the node's content.

b) There is a text file containing a serialized array. PHP script opens it
and deserializes the array into a variable; then, given an input string,
looks for an array element with the same key and returns the element's
value.

c) There is a PHP file containing just a definition for an array. PHP
script includes it and, given an input string, looks for an array element
with the same key and returns the element's value.

Does anyone have any idea which option would be the fastest, and which the
slowest of the three?

Thanks,

Berislav

Jul 17 '05 #2

P: n/a
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in
news:cj*******************@news.demon.co.uk:
Path:
phobos.telenet-ops.be!ossa.telenet-ops.be!feed1.news.be.easynet.net!new
s2.telebyte.nl!news.glorb.com!border1.nntp.dca.gig anews.com!nntp.gigane
ws.com!peer01.cox.net!cox.net!peer-uk.news.demon.net!kibo.news.demon.ne
t!news.demon.co.uk!demon!not-for-mail From: "Tony Marston"
<to**@NOSPAM.demon.co.uk> Newsgroups: comp.lang.php
Subject: Re: Performance inquiry
Date: Mon, 27 Sep 2004 11:03:03 +0100
Lines: 36
Message-ID: <cj*******************@news.demon.co.uk>
References: <k9****************************@40tude.net>
Reply-To: "Tony Marston" <to**@marston-home.demon.co.uk>
NNTP-Posting-Host: marston-home.demon.co.uk
X-Trace: news.demon.co.uk 1096279383 15906 80.177.120.119 (27 Sep 2004
10:03:03 GMT) X-Complaints-To: ab***@demon.net
NNTP-Posting-Date: Mon, 27 Sep 2004 10:03:03 +0000 (UTC)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Priority: 3
X-RFC2646: Format=Flowed; Original
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
Xref: ossa.telenet-ops.be comp.lang.php:69100

As you are clever enough to come up with that question why can't you
write the code to test each option yourself?


and post the results here ;-)
Jul 17 '05 #3

P: n/a
On Mon, 27 Sep 2004 10:57:16 +0200, Berislav Lopac
<be************@dimedia.hr> wrote:
Imagine three options:

a) There is an XML file. A PHP5 script loads it and puts it into a DOM
document object. Then, given an input string, a function looks via XPath
for a node with that name (or possibly value of an attribute) and returns
the node's content.

b) There is a text file containing a serialized array. PHP script opens
it
and deserializes the array into a variable; then, given an input string,
looks for an array element with the same key and returns the element's
value.

c) There is a PHP file containing just a definition for an array. PHP
script includes it and, given an input string, looks for an array element
with the same key and returns the element's value.

Does anyone have any idea which option would be the fastest, and which
the
slowest of the three?

Thanks,

Berislav


c > b > a
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 17 '05 #4

P: n/a
On Mon, 27 Sep 2004 13:47:15 +0200, Thomas Stian Bergheim wrote:
c > b > a


Sorry for splitting hairs here, but is there any empirical data behind it,
or is it just gut feeling (mine says so too)?

Berislav
Jul 17 '05 #5

P: n/a
"Berislav Lopac" <be************@dimedia.hr> wrote in message
news:1h******************************@40tude.net.. .
On Mon, 27 Sep 2004 13:47:15 +0200, Thomas Stian Bergheim wrote:
c > b > a


Sorry for splitting hairs here, but is there any empirical data behind it,
or is it just gut feeling (mine says so too)?


Unless you count " .. or I will eat my hat if it ain't so.." as empirical
expirience ;) .

I would expect the xml parsing to be the slowest, then array
deserialization, and hardcoded constant to be the fastest. Benchmarking xml
and deserialization should give some meaningfull results, hardcoded constant
should be more trickey, since zend or turk cache could be playing major
role.

rush
--
http://www.templatetamer.com/
Jul 17 '05 #6

P: n/a
Berislav Lopac wrote:
Imagine three options:

....cut...

Aren't we missing something here :-)
Are we talking about 10 nods/elements/whatever things or are we talking
about 10^10 elements?
I believe it does make a diference

gordan
Jul 17 '05 #7

P: n/a
On Mon, 27 Sep 2004 15:47:07 +0200, Gordan wrote:
Berislav Lopac wrote:
Imagine three options:

...cut...

Aren't we missing something here :-)
Are we talking about 10 nods/elements/whatever things or are we talking
about 10^10 elements?
I believe it does make a diference


For multi-level hierarchies, absolutely. I am right now interested only in
one-level ones, but I'd like to hear if anyone has some hard data for
either.

Berislav
Jul 17 '05 #8

P: n/a
"rush" <pi**@rush.avalon.hr> wrote in message
news:cj**********@ls219.htnet.hr...
"Berislav Lopac" <be************@dimedia.hr> wrote in message
news:1h******************************@40tude.net.. .
On Mon, 27 Sep 2004 13:47:15 +0200, Thomas Stian Bergheim wrote:
c > b > a
Sorry for splitting hairs here, but is there any empirical data behind it, or is it just gut feeling (mine says so too)?


Unless you count " .. or I will eat my hat if it ain't so.." as empirical
expirience ;) .

I would expect the xml parsing to be the slowest, then array
deserialization, and hardcoded constant to be the fastest. Benchmarking

xml and deserialization should give some meaningfull results, hardcoded constant should be more trickey, since zend or turk cache could be playing major
role.

rush
--
http://www.templatetamer.com/


Deserialization should be faster than an array in PHP code actually, since
there's no tokenizatin/compilation involved. The data is most densely packed
as well.
Jul 17 '05 #9

P: n/a
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:Po********************@comcast.com...
Deserialization should be faster than an array in PHP code actually, since
there's no tokenizatin/compilation involved. The data is most densely packed as well.


Well, turk cache or something similar would change that other way around,
that's why I have mentioned that benchmarking constants would be tricky.

rush
--
http://www.templatetamer.com/
Jul 17 '05 #10

P: n/a
"rush" <pi**@rush.avalon.hr> wrote in message news:<cj**********@ls219.htnet.hr>...
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:Po********************@comcast.com...
Deserialization should be faster than an array in PHP code actually, since
there's no tokenizatin/compilation involved. The data is most densely

packed
as well.


Well, turk cache or something similar would change that other way around,
that's why I have mentioned that benchmarking constants would be tricky.

rush


I doubt it. Even if caching is present, you wouldn't have the array
just sitting in memory. PHP is not C after all. A array declaration is
a chunk of code, where each element is an expression. To instancize
the array, the PHP interpreter has to evaluate the code, which
obviously take time.

The following is a little benchmark comparing unserialize() with
array():

$x = serialize(array( 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello'
));

$s = time();

for($i = 0; $i < 2000000; $i++) {
$a = unserialize($x);
}

$e = time();
$d = $e - $s;

echo "$d<br>";

$s = time();

for($i = 0; $i < 2000000; $i++) {
$a = array( 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello' );
}

$e = time();
$d = $e - $s;

echo "$d<br>";

The first loop required 30 sec while the second took 26 sec. Even
under this ideal situation the array declaration isn't that much
faster. Add in any cache overhead (mtime check, for instance) and
it'll end up being slower.
Jul 17 '05 #11

P: n/a
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:a1**************************@posting.google.c om...
"rush" <pi**@rush.avalon.hr> wrote in message

news:<cj**********@ls219.htnet.hr>...
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:Po********************@comcast.com...


I doubt it. Even if caching is present, you wouldn't have the array
just sitting in memory. PHP is not C after all. A array declaration is
a chunk of code, where each element is an expression. To instancize
the array, the PHP interpreter has to evaluate the code, which
obviously take time.


Well I can agree that issue is at least very tricky. But, I was doing quite
a lot of testing for TT, to find out if it is more effcient to load template
string from file, or as constant in php code. The results were not a clear
cut, but when php accelerator was present, code variant seemed to be faster
on average.

rush
--
http://www.templatetamer.com/
Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.