Adding idle timeout capabilities to asyncore

Jean-Paul Calderone exarkun at divmod.com
Tue Oct 23 12:30:46 EDT 2007


On Tue, 23 Oct 2007 15:34:19 -0000, Josiah Carlson <josiah.carlson at gmail.com> wrote:
> [snip]
>
>Calling time.time() is relatively inexpensive in comparison to pure
>Python function calls, but indeed, it could be a bottleneck.

Did you benchmark this on some system?

There isn't really any "pure Python function calls" that can replace
time.time() in a sensible way, so I made up one that does some random
things (including calling another Python function) and compared it to
time.time:

  exarkun at charm:~$ python -m timeit -s '
  def g():
      return 1. + 2 + 3 * 4 - 5 / 6 + 7 ** 8
  def f():
      return g()
  ' 'f()'
  1000000 loops, best of 3: 1.39 usec per loop
  exarkun at charm:~$ python -m timeit -s 'from time import time as f' 'f()'
  100000 loops, best of 3: 4.68 usec per loop
  exarkun at charm:~$

Not really useful in any real-world sense, but I still wouldn't
characterize time.time as "relatively inexpensive."

Of course, for any real-world work, one would want to profile the
application to determine if removing calls to time.time() could
make a worthwhile difference.

Jean-Paul



More information about the Python-list mailing list