Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion PyEval_SetProfile usage ?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Thomas Jollans  
View profile  
 More options Jul 7 2012, 5:50 am
Newsgroups: comp.lang.python
From: Thomas Jollans <t...@jollybox.de>
Date: Sat, 07 Jul 2012 11:50:05 +0200
Local: Sat, Jul 7 2012 5:50 am
Subject: Re: PyEval_SetProfile usage ?
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
*/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.