What performs better, theoreticaly?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rolf Mander

    What performs better, theoreticaly?

    What performs better, theoreticaly?
    This
    <?
    echo date("d",time() );
    echo date("m",time() );
    echo date("Y",time() );
    ?>
    Or that?
    <?
    $time = time();
    echo date("d",$time) ;
    echo date("m",$time) ;
    echo date("Y",$time) ;
    ?>
    when does it get relevant?
    thanks
    Rolf


  • ZeldorBlat

    #2
    Re: What performs better, theoreticaly?

    On Apr 23, 10:39 am, "Rolf Mander" <rolf.man...@sp am.comwrote:
    What performs better, theoreticaly?
    This
    <?
    echo date("d",time() );
    echo date("m",time() );
    echo date("Y",time() );
    ?>
    Or that?
    <?
    $time = time();
    echo date("d",$time) ;
    echo date("m",$time) ;
    echo date("Y",$time) ;
    ?>
    when does it get relevant?
    thanks
    Rolf
    Theoretically the second one, since you only need to make 4 function
    calls instead of six. It won't be relevant anytime soon.

    Comment

    • Paul Herber

      #3
      Re: What performs better, theoreticaly?

      On Mon, 23 Apr 2007 16:39:00 +0200, "Rolf Mander"
      <rolf.mander@sp am.comwrote:
      >What performs better, theoreticaly?
      >This
      ><?
      >echo date("d",time() );
      >echo date("m",time() );
      >echo date("Y",time() );
      >?>
      there's a bug just waiting to happen, ok, only once per month at
      midnight on the last day of the month.


      --
      Regards, Paul Herber, Sandrila Ltd.
      Electronics for Visio http://www.electronics.sandrila.co.uk/

      Comment

      • ZeldorBlat

        #4
        Re: What performs better, theoreticaly?

        On Apr 23, 11:06 am, Paul Herber
        <SubstituteMyFi rstNameH...@phe rber.comwrote:
        On Mon, 23 Apr 2007 16:39:00 +0200, "Rolf Mander"
        >
        <rolf.man...@sp am.comwrote:
        What performs better, theoreticaly?
        This
        <?
        echo date("d",time() );
        echo date("m",time() );
        echo date("Y",time() );
        ?>
        >
        there's a bug just waiting to happen, ok, only once per month at
        midnight on the last day of the month.
        >
        --
        Regards, Paul Herber, Sandrila Ltd.
        Electronics for Visio http://www.electronics.sandrila.co.uk/
        And assuming you run the script at exactly the right millisecond.

        Comment

        • Toby A Inkster

          #5
          Re: What performs better, theoreticaly?

          Rolf Mander wrote:
          <?
          echo date("d",time() );
          echo date("m",time() );
          echo date("Y",time() );
          ?>
          Consider running this code at the stroke of midnight on Monday/Tuesday
          next week.

          <?
          /* Today is Monday 30 April 2007 */
          echo date("d",time() );
          /* It's midnight now. Clocks go 23:59:59 =00:00:00. */
          /* Today is Tuesday 1 May 2007 */
          echo date("m",time() );
          echo date("Y",time() );
          ?>

          Outputs: 30052007

          The other code you posted:
          <?
          $time = time();
          echo date("d",$time) ;
          echo date("m",$time) ;
          echo date("Y",$time) ;
          ?>
          Doesn't suffer from that problem. It's also probably faster, but unless
          you're doing it thousands of times in a loop, you won't notice any
          difference.

          --
          Toby A Inkster BSc (Hons) ARCS
          Fast withdrawal casino UK 2025 – Play now & cash out instantly! Discover the top sites for rapid, secure payouts with no delays.

          Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

          * = I'm getting there!

          Comment

          • NC

            #6
            Re: What performs better, theoreticaly?

            On Apr 23, 7:39 am, "Rolf Mander" <rolf.man...@sp am.comwrote:
            What performs better, theoreticaly?
            >
            echo date("d",time() );
            echo date("m",time() );
            echo date("Y",time() );
            >
            Or that?
            >
            $time = time();
            echo date("d",$time) ;
            echo date("m",$time) ;
            echo date("Y",$time) ;
            Theoretically (and assuming that your question is more general than
            the example you gave), it depends on what system resource is
            constrained. If it is memory, the first would work better (there is
            no additional variable required); if it is CPU, the second is better
            (one function call instead of three).
            when does it get relevant?
            Very rarely, unless you are building something quantitative. The
            resource that usually gets constained first is disk I/O.

            Cheers,
            NC

            Comment

            • =?ISO-8859-15?Q?Oliver_Gr=E4tz?=

              #7
              Re: What performs better, theoreticaly?

              Rolf Mander schrieb:
              What performs better, theoreticaly?
              This
              <?
              echo date("d",time() );
              echo date("m",time() );
              echo date("Y",time() );
              ?>
              Or that?
              <?
              $time = time();
              echo date("d",$time) ;
              echo date("m",$time) ;
              echo date("Y",$time) ;
              ?>
              Like others already told you: The first version produces a race
              condition when being run over a date change.

              And perhaps you might consider using $_SERVER['REQUEST_TIME'] which
              contains the timestamp of the begin of the request...

              OLLi

              --
              Bree: "Oh, hello."
              Bartender: "Hi."
              Bree: "Hi. Um, I need some advice from a professional. I'd like to get
              stinking drunk. Do you have anything that can accomplish that in a hurry?"
              [DH 218]

              Comment

              • nice.guy.nige

                #8
                Re: What performs better, theoreticaly?

                While the city slept, Toby A Inkster (usenet200703@t obyinkster.co.u k)
                feverishly typed...

                [...]
                It's also probably faster, but unless you're doing it
                thousands of times in a loop, you won't notice
                any difference.
                Except, of course, if this is a web application, it is possible for
                thousands of users to want to run it at the same time ;-)

                Cheers,
                Nige

                --
                Nigel Moss http://www.nigenet.org.uk
                Mail address will bounce. nigel@DOG.nigen et.org.uk | Take the DOG. out!
                "Your mother ate my dog!", "Not all of him!"


                Comment

                Working...