Programmatic timing of execution using profiler

Martin Christensen knightsofspamalot-factotum at gvdnet.dk
Fri Dec 27 20:36:53 EST 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Howdy!

I have written a keyword-based search engine in Python and am running
some experiments which I want to time. The Python profiler seems to be
better for this purpose than both the clock-on-the-wall method and
systime1 - systime0. However, I am having some problems automating the
process. A simplified example is given in the following code:

##########
import profile

def test(niftyobject, x):
    # Do some test stuff.
    # ...
    pass

def runtests(niftyobject, testcases):
    for i in testcases:
        # Run a test and write the profile info to a file.
        profile.run(('test(niftyobject, %s)' % str(i)), ('%s.prof' % str(i)))
        #                  ^^^^^^^^^^^

runtests(someobj(), [1, 5, 10, 'a'])
##########

Here I get a NameError on niftyobject, which the profiler does not
recognise as being defined.

If anyone can suggest a way to get this running, or possibly a better
way of measuring execution time, I would be grateful, even more so if
replies be speedy... Deadline, thou art a harsh mistress! :-)

Martin

- -- 
Homepage:       http://www.cs.auc.dk/~factotum/
GPG public key: http://www.cs.auc.dk/~factotum/gpgkey.txt
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG <http://www.gnupg.org>

iEYEARECAAYFAj4NADUACgkQYu1fMmOQldV6NACeKKNHFoGBm/LkM8eSQnLwOkXF
ELoAoMBnFA0D3ejvqAf42t4i5aQeHK2C
=Rlpa
-----END PGP SIGNATURE-----



More information about the Python-list mailing list