Lockless algorithms in python (Nothing to do with GIL)

Antoine Pitrou solipsis at pitrou.net
Fri Jul 2 16:26:03 EDT 2010


On Mon, 28 Jun 2010 16:46:41 -0700
Zac Burns <zac256 at gmail.com> wrote:
> In my experience it is far more expensive to allocate a lock in python then
> it is the types that use them. Here are some examples:
> 
> >>> timeit.timeit('Lock()', 'from threading import Lock')
> 1.4449114807669048
> 
> >>> timeit.timeit('dict()')
> 0.2821554294221187
> 
> >>> timeit.timeit('list()')
> 0.17358153222312467

I'm not sure what Python version on what machine you are using, but
here (Python 2.7):

>>> timeit.timeit('Lock()', 'from threading import Lock')
0.09944796562194824
>>> timeit.timeit('dict()')
0.17817902565002441
>>> timeit.timeit('list()')
0.19633007049560547
>>> timeit.timeit('{}')
0.03823709487915039
>>> timeit.timeit('[]')
0.05156302452087402






More information about the Python-list mailing list