Re: PyEval_SetProfile usage ?

Discussion in 'Python' started by Thomas Jollans, Jul 7, 2012.

  1. On 07/06/2012 11:40 PM, Salman Malik wrote:
    > Hi All,
    >
    > I have used the Python's C-API to call some Python code in my c code and
    > now I want to know how much time does my Python part of the program
    > takes. I came across the PyEval_SetProfile API and am not sure how to
    > use it. Do I need to write my own profiling function?


    You could have a look at the source code of the cProfile extension
    module. I assume it uses the feature.

    In your case, what's wrong with simply measuring the time?


    /* variables. */
    unsigned long delta_usec;
    struct timeval t1, t2;

    /* get start time */
    gettimeofday (&t1, NULL);

    /* DO PYTHON STUFF */

    /* get end time */
    gettimeofday (&t2, NULL);

    /* delta? */
    delta_usec = (t2.tv_sec - t1.tv_sec) * 1000
    + (signed)(t2.tv_usec - t1.tv_usec);

    /* if your Python code is called multiple times, do this for each one,
    and (if you like) sum up the result. It's simpe enough, and you
    don't have to mess with profiling function.
    Alternatively, you could use a C profiler like Valgrind
    */
     
    Thomas Jollans, Jul 7, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. metfan
    Replies:
    2
    Views:
    4,865
    Robert Olofsson
    Oct 21, 2003
  2. Colin J. Williams

    Webchecker Usage - a problem with local usage

    Colin J. Williams, Feb 25, 2004, in forum: Python
    Replies:
    1
    Views:
    556
    Colin J. Williams
    Feb 26, 2004
  3. hvt
    Replies:
    0
    Views:
    1,221
  4. hvt
    Replies:
    0
    Views:
    1,499
  5. Krist
    Replies:
    8
    Views:
    6,606
    Arne Vajhøj
    Feb 10, 2010
Loading...

Share This Page