Jean-Paul Calderone <exar...@divmod.com> added the comment:

For what it's worth, here are some timings from my system.  First,
os.kill without raising an exception:

exar...@boson:~$ python -m timeit -s 'import os; pid = os.getpid()' '
os.kill(pid, 0)
'
1000000 loops, best of 3: 0.413 usec per loop
exar...@boson:~$ 

Next, os.kill without raising an exception, but with exception handling:

exar...@boson:~$ python -m timeit -s 'import os; pid = os.getpid()' '
> try:
>     os.kill(pid, 0)
> except OSError, e:
>     pass
> '
1000000 loops, best of 3: 0.42 usec per loop

Finally, os.kill with exception handling and raising an exception:

exar...@boson:~$ python -m timeit -s 'import os; pid = os.getpid()' '
try:
    os.kill(pid + 1, 0)
except OSError, e:
    pass
'
100000 loops, best of 3: 2.58 usec per loop

The slowest case is almost 7x slower than the fastest case.  However,
this is only triggered when os.kill raises an exception (ie, if the pid
does exist, it's still fast).  Plus, this "slow" case still only takes
two and a half microseconds.  That's pretty fast.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6554>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to