STINNER Victor added the comment:

list: items are allocated in a second memory block. PyList_New() uses memset(0) 
to set all items to NULL.

tuple: header and items are stored in a single structure (PyTupleObject), in a 
single memory block. PyTuple_New() fills the items will NULL (so write again 
null bytes). Something can be optimized here.

dict: header, keys and values are stored in 3 different memory blocks. It may 
be interesting to use calloc() to allocate keys and values. Initialization of 
keys and values to NULL uses a dummy loop. I expect that memset(0) would be 
faster.

Anyway, I expect that all items of builtin containers (tuple, list, dict, etc.) 
are set to non-NULL values. So the lazy initialization to zeros may be useless 
for them.

It means that benchmarking builtin containers should not show any speedup. 
Something else (numpy?) should be used to see an interesting speedup.

----------

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

Reply via email to