Performance inquiry

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Berislav Lopac

    Performance inquiry

    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
  • Tony Marston

    #2
    Re: Performance inquiry

    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

    This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




    "Berislav Lopac" <berislav.lopac @dimedia.hr> wrote in message
    news:k9hxyjv8s1 pu.1xt3kn262k71 c.dlg@40tude.ne t...[color=blue]
    > 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[/color]


    Comment

    • Ward

      #3
      Re: Performance inquiry

      "Tony Marston" <tony@NOSPAM.de mon.co.uk> wrote in
      news:cj8ogn$fh2 $1$8302bc10@new s.demon.co.uk:
      [color=blue]
      > Path:
      > phobos.telenet-ops.be!ossa.tel enet-ops.be!feed1.ne ws.be.easynet.n et!new
      > s2.telebyte.nl! news.glorb.com! border1.nntp.dc a.giganews.com! nntp.gigane
      > ws.com!peer01.c ox.net!cox.net! peer-uk.news.demon.n et!kibo.news.de mon.ne
      > t!news.demon.co .uk!demon!not-for-mail From: "Tony Marston"
      > <tony@NOSPAM.de mon.co.uk> Newsgroups: comp.lang.php
      > Subject: Re: Performance inquiry
      > Date: Mon, 27 Sep 2004 11:03:03 +0100
      > Lines: 36
      > Message-ID: <cj8ogn$fh2$1$8 302bc10@news.de mon.co.uk>
      > References: <k9hxyjv8s1pu.1 xt3kn262k71c.dl g@40tude.net>
      > Reply-To: "Tony Marston" <tony@marston-home.demon.co.u k>
      > NNTP-Posting-Host: marston-home.demon.co.u k
      > X-Trace: news.demon.co.u k 1096279383 15906 80.177.120.119 (27 Sep 2004
      > 10:03:03 GMT) X-Complaints-To: abuse@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:6 9100
      >
      > As you are clever enough to come up with that question why can't you
      > write the code to test each option yourself?
      >[/color]

      and post the results here ;-)

      Comment

      • Thomas Stian Bergheim

        #4
        Re: Performance inquiry

        On Mon, 27 Sep 2004 10:57:16 +0200, Berislav Lopac
        <berislav.lopac @dimedia.hr> wrote:
        [color=blue]
        > 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[/color]

        c > b > a


        --
        Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

        Comment

        • Berislav Lopac

          #5
          Re: Performance inquiry

          On Mon, 27 Sep 2004 13:47:15 +0200, Thomas Stian Bergheim wrote:
          [color=blue]
          > c > b > a[/color]

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

          Berislav

          Comment

          • rush

            #6
            Re: Performance inquiry

            "Berislav Lopac" <berislav.lopac @dimedia.hr> wrote in message
            news:1hsnmld88p qoa$.1cjdqlsuih vrk.dlg@40tude. net...[color=blue]
            > On Mon, 27 Sep 2004 13:47:15 +0200, Thomas Stian Bergheim wrote:
            >[color=green]
            > > c > b > a[/color]
            >
            > Sorry for splitting hairs here, but is there any empirical data behind it,
            > or is it just gut feeling (mine says so too)?[/color]

            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
            --
            Get your very own domain easily. Fast and professional customer service.



            Comment

            • Gordan

              #7
              Re: Performance inquiry

              Berislav Lopac wrote:[color=blue]
              > Imagine three options:[/color]
              ....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


              Comment

              • Berislav Lopac

                #8
                Re: Performance inquiry

                On Mon, 27 Sep 2004 15:47:07 +0200, Gordan wrote:
                [color=blue]
                > Berislav Lopac wrote:[color=green]
                >> Imagine three options:[/color]
                > ...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[/color]

                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

                Comment

                • Chung Leong

                  #9
                  Re: Performance inquiry

                  "rush" <pipa@rush.aval on.hr> wrote in message
                  news:cj93ok$6n1 $1@ls219.htnet. hr...[color=blue]
                  > "Berislav Lopac" <berislav.lopac @dimedia.hr> wrote in message
                  > news:1hsnmld88p qoa$.1cjdqlsuih vrk.dlg@40tude. net...[color=green]
                  > > On Mon, 27 Sep 2004 13:47:15 +0200, Thomas Stian Bergheim wrote:
                  > >[color=darkred]
                  > > > c > b > a[/color]
                  > >
                  > > Sorry for splitting hairs here, but is there any empirical data behind[/color][/color]
                  it,[color=blue][color=green]
                  > > or is it just gut feeling (mine says so too)?[/color]
                  >
                  > 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[/color]
                  xml[color=blue]
                  > and deserialization should give some meaningfull results, hardcoded[/color]
                  constant[color=blue]
                  > should be more trickey, since zend or turk cache could be playing major
                  > role.
                  >
                  > rush
                  > --
                  > http://www.templatetamer.com/
                  >[/color]

                  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.


                  Comment

                  • rush

                    #10
                    Re: Performance inquiry

                    "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
                    news:Po-dnT2s4eJIssfcRV n-rg@comcast.com. ..[color=blue]
                    > Deserialization should be faster than an array in PHP code actually, since
                    > there's no tokenizatin/compilation involved. The data is most densely[/color]
                    packed[color=blue]
                    > as well.[/color]

                    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
                    --
                    Get your very own domain easily. Fast and professional customer service.



                    Comment

                    • Chung Leong

                      #11
                      Re: Performance inquiry

                      "rush" <pipa@rush.aval on.hr> wrote in message news:<cjdqff$d9 a$1@ls219.htnet .hr>...[color=blue]
                      > "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
                      > news:Po-dnT2s4eJIssfcRV n-rg@comcast.com. ..[color=green]
                      > > Deserialization should be faster than an array in PHP code actually, since
                      > > there's no tokenizatin/compilation involved. The data is most densely[/color]
                      > packed[color=green]
                      > > as well.[/color]
                      >
                      > 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[/color]

                      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.

                      Comment

                      • rush

                        #12
                        Re: Performance inquiry

                        "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
                        news:a164f4b5.0 409291026.66a55 0e7@posting.goo gle.com...[color=blue]
                        > "rush" <pipa@rush.aval on.hr> wrote in message[/color]
                        news:<cjdqff$d9 a$1@ls219.htnet .hr>...[color=blue][color=green]
                        > > "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
                        > > news:Po-dnT2s4eJIssfcRV n-rg@comcast.com. ..[/color]
                        >
                        > 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.[/color]

                        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
                        --
                        Get your very own domain easily. Fast and professional customer service.



                        Comment

                        Working...