473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Possible inaccuracy in Python 2.4 when using profiler calibration

I have a misinformed theory that I'd like to share with the list.

I believe that profiler calibration no longer makes sense in Python 2.4
because C functions are tracked and they have a different call overhead
than Python functions (and calibration is done only using Python
functions). Here is my reasoning (in code form):

% c:\python24\python
....
import profile
p = profile.Profile()
for i in range(5):

.... print p.calibrate(1000000)
....
4.00375499355e-006
3.95700929469e-006
3.94034406478e-006
4.00315854962e-006
3.99454335716e-006

Code
----
import profile
profile.Profile.bias = 3.90e-006 # very conservative

def bar():
l = []
for i in range(100000):
l += [i]

def foo():
l = []
for i in range(100000):
l.append(i) # C function that can be tracked

def baz():
bar()
foo()

profile.run('baz()', "out.prof")
from pstats import Stats
s = Stats('out.prof')
s.sort_stats('time', 'calls')
s.print_stats()

from timeit import Timer

t1 = Timer(
'bar()', 'from __main__ import bar',)
print 'bar():', t1.timeit(1000) / 1000

t2 = Timer(
'foo()', 'from __main__ import foo',)
print 'foo():', t2.timeit(1000) / 1000

Output
------

Thu Jun 15 10:22:29 2006 out.prof

100008 function calls in -0.090 CPU seconds

Ordered by: internal time, call count

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.058 0.058 0.062 0.062 cal-test.py:4(bar)
2 0.006 0.003 0.006 0.003 :0(range)
1 0.004 0.004 -0.090 -0.090 cal-test.py:14(baz)
1 0.001 0.001 0.001 0.001 :0(setprofile)
1 0.000 0.000 -0.090 -0.090 profile:0(baz())
1 0.000 0.000 -0.090 -0.090 <string>:1(?)
0 0.000 0.000 profile:0(profiler)
1 -0.066 -0.066 -0.157 -0.157 cal-test.py:9(foo)
100000 -0.094 -0.000 -0.094 -0.000 :0(append)
bar(): 0.0582713573932
foo(): 0.0370039776005

Analysis
--------

As you can see, the profiler result for "bar" is pretty reasonable but
it is not for "foo" or "append". I believe that is because the calling
of the C function "append" takes less time than is accounted for in the
bias measurement (which was generated by measuring the call time of a
Python function).

So the bias computation doesn't make sense in Python 2.4.

What do y'all think? Is this a well known fact? Should I construct a
test to see if C function call overhead is actually less than Python
function call overhead?

Cheers,
Brian
Jun 15 '06 #1
1 1389
Brian Quinlan <br***@sweetapp.com> writes on Thu, 15 Jun 2006 10:36:26 +0200:
I have a misinformed theory that I'd like to share with the list.

I believe that profiler calibration no longer makes sense in Python
2.4 because C functions are tracked and they have a different call
overhead than Python functions (and calibration is done only using
Python functions). Here is my reasoning (in code form):


I fear it never made sense -- even with pure Python functions:

I tried to calibrate under Linux and failed miserably:
apparently, the "clock" resolution is very coarse
introducing a very high variance which is very bad for
calibration.
Jun 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicolas Lehuen | last post by:
Hi, Is it me, or does anyone else get significantly better pystone results under Cygwin versus the standard Win32 build ? CYGWIN 1.5.6 + python 2.3.3-1 : $ time python...
1
by: Scott Brady Drummonds | last post by:
Hi, everyone, I have a tool I've written in Python that is taking many hours to run but I believe could be running in less than an hour with a more clever implementation. As such, I'm trying to...
6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
2
by: Celine & Dave | last post by:
Hello All, I am trying to find a profiler that can measure the memory usage in a Python program. I would like to gather some statistics about object usages. For example, I would like to be able...
7
by: flupke | last post by:
Hi, i'm getting errors with the log module concerning RotatingFileHandler. I'm using Python 2.4.3 on Windows XP SP2. This used to work in previous python versions but since i upgraded to 2.4.3...
3
by: looping | last post by:
Hi, I noticed a big speed improvement in some of my script that use os.walk and I write a small script to check it: import os for path, dirs, files in os.walk('D:\\FILES\\'): pass Results on...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 407 open ( +1) / 3484 closed ( +5) / 3891 total ( +6) Bugs : 936 open ( +5) / 6363 closed (+14) / 7299 total (+19) RFE : 246 open...
11
by: Ben | last post by:
Here are the statistics from Google Trends: http://benyang22a.blogspot.com/2007/09/perl-vs-python.html
2
DonRayner
by: DonRayner | last post by:
This one has me stumped. I'm getting a "Type Mismatch" error on one of my forms when it's being opened. It's hapening before the forms "On Open" event, I stuck a msgbox in there to check and I'm...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.