[TIP] Interesting getattr pattern [was: Re: [issue5728] Support telling TestResult objects a test run has finished]

John Arbash Meinel john at arbash-meinel.com
Tue Apr 14 10:06:48 PDT 2009

Hash: SHA1

Olemis Lang wrote:
> On Mon, Apr 13, 2009 at 9:10 AM, Olemis Lang <olemis at gmail.com> wrote:
>> According to my experience, function calls are expensive, especially
>> in this case where startTestRun method can be called *MANY* times.
> I tried to measure the three candidate alternatives. I employed a
> simpler example (didnt remember the whole code :-/ , and this was done
> yesterday ) :

> Possible conclusions :
> - func1 seems to be the fastest
> - func2 seems to be quite cool
> - func3 seems to be the slowest
> ... from there on it's up to you anyway.

I would just mention that I would trust "python -mtimeit" runs more than
runs using cProfile.run. Just because adding the profiler tends to skew
things a bit. In general, it makes function call overhead *even greater*
than without the profiler. So inline actions like dict[] versus
dict.get() are generally a bit biased.

I would imagine that getattr() versus foo.attr are going to at least
have a slight bias when run under a profiler.


Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the testing-in-python mailing list