Lockless algorithms in python (Nothing to do with GIL)

Zac Burns zac256 at gmail.com
Tue Jul 6 13:06:18 EDT 2010


I'm not an expert on this, but wouldn't it be more dependent on the platform
than python version? Perhaps it is Windows 7 that is very slow. Perhaps my
processor architecture. Not sure...

Here are some for 3.1.2x64

>>> import timeit
>>> timeit.timeit('Lock()', 'from threading import Lock')
1.4162585386092708
>>> timeit.timeit('dict()', 'from threading import Lock')
0.2730348901369162
>>> timeit.timeit('list()', 'from threading import Lock')
0.1719480219512306

-Zac

On Fri, Jul 2, 2010 at 1:26 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:

> 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
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100706/e2445b2f/attachment.html>


More information about the Python-list mailing list