Execution time of lines within a function

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

    #1

    Execution time of lines within a function

    Hello,

    I have a function that hotshot says is very slow. I can get the
    aggregate execution time, but is there a way to get the execution time
    of each line so I can find the bottleneck?

    Thank you

  • Neil Cerutti

    #2
    Re: Execution time of lines within a function

    On 2006-12-04, monkeyboy <fsenkel@lynx.n eu.eduwrote:
    I have a function that hotshot says is very slow. I can get the
    aggregate execution time, but is there a way to get the
    execution time of each line so I can find the bottleneck?
    Try 'print_callees' on the stats object for your bottleneck. That
    may help.

    --
    Neil Cerutti

    Comment

    • monkeyboy

      #3
      Re: Execution time of lines within a function

      Thanks Neil,

      I looked at that, but maybe I don't understand the output. I was hoping
      to see the cummulative time for the function and then the time
      associated with each statement (line) within the function.

      In the hotshot output below, I can see the function being called 100
      times, which is correct, but the rest seems at too low a level for me
      to understand which statements are causing the slow execution.

      Any suggestions?

      hw6r3.py:276(ma in) hw6r3.py:73(fin dw)(100) 26700.865
      hw6r3.py:126(fi ndphi)(100)
      6153.585
      hw6r3.py:173(fi ndu)(100) 1823.852
      hw6r3.py:197(fi ndv)(100) 2392.977
      numeric.py:31(z eros_like)(3)
      0.072
      numeric.py:286( array_str)(1)
      0.677
      rpc.py:545(__ge tattr__)(13)
      0.197
      rpc.py:589(__ca ll__)(12) 51.334
      rpc.py:319(putm essage) <string>:1(file no)(12) 0.039
      rpc.py:149(debu g)(12) 0.126
      rpc.py:236(asyn creturn) rpc.py:149(debu g)(24) 0.126
      rpc.py:242(deco deresponse)(12)
      0.015
      rpc.py:277(getr esponse)(12)
      48.166


      Regards,

      Frank

      Neil Cerutti wrote:
      On 2006-12-04, monkeyboy <fsenkel@lynx.n eu.eduwrote:
      I have a function that hotshot says is very slow. I can get the
      aggregate execution time, but is there a way to get the
      execution time of each line so I can find the bottleneck?
      >
      Try 'print_callees' on the stats object for your bottleneck. That
      may help.
      >
      --
      Neil Cerutti

      Comment

      • Neil Cerutti

        #4
        Re: Execution time of lines within a function

        On 2006-12-04, monkeyboy <fsenkel@lynx.n eu.eduwrote:
        Thanks Neil,
        >
        I looked at that, but maybe I don't understand the output. I
        was hoping to see the cummulative time for the function and
        then the time associated with each statement (line) within the
        function.
        >
        Any suggestions?
        I don't think the Python Profiler goes down to that level. The
        next step might be to analyze the function yourself and try to
        understand why it is so slow. Post the code here and let the
        readers pick it apart.
        In the hotshot output below, I can see the function being
        called 100 times, which is correct, but the rest seems at too
        low a level for me to understand which statements are causing
        the slow execution.
        >
        hw6r3.py:276(ma in) hw6r3.py:73(fin dw)(100) 26700.865
        Is this the print_callees output?

        --
        Neil Cerutti

        Comment

        • monkeyboy

          #5
          Re: Execution time of lines within a function

          The output was from print_callees() . It appears as though print_stats()
          and print_callees() return the same data, just in a different
          orangization. There is supposed to be a "lineevents =1" option in
          hotshot.Profile , for line timings, but it doesn't seem to work in
          Python 2.4.

          Thanks for your help

          Neil Cerutti wrote:
          On 2006-12-04, monkeyboy <fsenkel@lynx.n eu.eduwrote:
          Thanks Neil,

          I looked at that, but maybe I don't understand the output. I
          was hoping to see the cummulative time for the function and
          then the time associated with each statement (line) within the
          function.

          Any suggestions?
          >
          I don't think the Python Profiler goes down to that level. The
          next step might be to analyze the function yourself and try to
          understand why it is so slow. Post the code here and let the
          readers pick it apart.
          >
          In the hotshot output below, I can see the function being
          called 100 times, which is correct, but the rest seems at too
          low a level for me to understand which statements are causing
          the slow execution.
          >
          >

          hw6r3.py:276(ma in) hw6r3.py:73(fin dw)(100) 26700.865
          >
          Is this the print_callees output?
          >
          --
          Neil Cerutti

          Comment

          • Paul McGuire

            #6
            Re: Execution time of lines within a function

            "monkeyboy" <fsenkel@lynx.n eu.eduwrote in message
            news:1165240166 .203915.115460@ n67g2000cwd.goo glegroups.com.. .
            Hello,
            >
            I have a function that hotshot says is very slow. I can get the
            aggregate execution time, but is there a way to get the execution time
            of each line so I can find the bottleneck?
            >
            Thank you
            >
            The PythonDecorator Library page on the Python wiki has a link to a @profile
            decorator, that I have used to profile the contents of targeted functions
            (only just now, I don't seem to be able to get to the wiki to get the exact
            link).

            -- Paul


            Comment

            • Ed Leafe

              #7
              Re: Execution time of lines within a function

              On Dec 4, 2006, at 11:36 PM, Paul McGuire wrote:
              The PythonDecorator Library page on the Python wiki has a link to a
              @profile
              decorator, that I have used to profile the contents of targeted
              functions
              (only just now, I don't seem to be able to get to the wiki to get
              the exact
              link).


              Note that the license has been changed from GPL to MIT, making it
              distributable with non-GPL projects.

              -- Ed Leafe
              -- http://leafe.com
              -- http://dabodev.com


              Comment

              Working...