How many lines of code get run when my script executes?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    How many lines of code get run when my script executes?

    Whew! Just got done writing the latest version of my template rendering engine, and it is a BEAST!

    I'm very proud of it, and hopefully with my boss' permission, I will be able to open source it soon. But that's not what my question is about.

    The class by itself is a little over 1500 lines of code, but I'm pretty sure that PHP actually ends up executing about 5 or 6 thousand lines of code before the first line of HTML gets output (and all in about a quarter of a second [1/8th after the first execution with Zend Optimizer!]... wow!).

    Out of curiosity, though, I'd love to know exactly how many lines of code PHP is executing per execution.

    Is there a tool out there that can do this? Preferably for Mac / *n?x platforms.

    Thanks for your time.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    I think I might have found something built into PHP that can do this:
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    Not sure exactly how to make it do what I want it to, but we'll have some fun, I'm sure!

    Comment

    • gregerly
      Recognized Expert New Member
      • Sep 2006
      • 192

      #3
      Originally posted by pbmods
      Whew! Just got done writing the latest version of my template rendering engine, and it is a BEAST!

      I'm very proud of it, and hopefully with my boss' permission, I will be able to open source it soon. But that's not what my question is about.

      The class by itself is a little over 1500 lines of code, but I'm pretty sure that PHP actually ends up executing about 5 or 6 thousand lines of code before the first line of HTML gets output (and all in about a quarter of a second [1/8th after the first execution with Zend Optimizer!]... wow!).

      Out of curiosity, though, I'd love to know exactly how many lines of code PHP is executing per execution.

      Is there a tool out there that can do this? Preferably for Mac / *n?x platforms.

      Thanks for your time.
      Nice work pbmods... I remember a big project I worked on when I first started programming PHP, I wrote like 600 lines without ever testing it. I was extatic when it worked the first time! I then realized how stupid that was and vowed never to do that again. Glad to hear about your successful project! Congrats!

      Greg

      Comment

      • jx2
        New Member
        • Feb 2007
        • 228

        #4
        Originally posted by pbmods
        The class by itself is a little over 1500 lines of code, but I'm pretty sure that PHP actually ends up executing about 5 or 6 thousand lines of code before the first line of HTML gets output (and all in about a quarter of a second [1/8th after the first execution with Zend Optimizer!]... wow!).
        sounds interesting :-)
        but ...
        What the zend optimizer is?

        regards jx2

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, jx2.

          Zend Optimizer is a PHP extension that caches opcode and performs runtime optimizations on PHP code. The end result is that after the first execution, each of your scripts executes much more quickly.

          You can find out more about this free utility here:
          Zend Guard is a tool for protecting PHP code — and preventing reverse engineering and unauthorized use of your PHP applications. Learn more.

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            Hehe I just wrote (and re-wrote three times) a template engine. It only handles conditional statements and looping, but that's all I need so far.

            I had it output the entire process once and it chains together multiple templates, parsing and injecting and it does a lot more work than I thought it did in such a short time. Like, 3 seconds in all. Tokenization.. Parsing.. Output... 2 - 5 seconds. Yet, I have another script that takes forever just to print <div>s to the browser window. It's 1000 <div>s, but still. It's like, 3 seconds per 100 <div>s.

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Looks like something like this should work, except, what it's counting is number of low-level instructions, not necessarily lines.

              [code=php]
              function countLine($dump = false)
              {
              static $lineCount = 0;

              if($dump)
              {
              return $lineCount;
              }

              ++$lineCount;
              }

              register_tick_f unction('countL ine');
              declare(ticks = 1);

              .
              .
              .

              echo countLine(true) , ' lines of code executed.';
              [/code]

              Comment

              Working...