[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-21 Thread Steven D'Aprano
On Fri, Feb 21, 2020 at 02:42:16PM +0200, Serhiy Storchaka wrote: > 21.02.20 10:36, Steven D'Aprano пише: > >On my machine, at least, constructing a bytes object first followed by > >an array is significantly faster than the alternative: > > > >[steve@ando cpython]$ ./python -m timeit -s "from

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-21 Thread Stephan Hoyer
On Fri, Feb 21, 2020 at 12:43 AM Steven D'Aprano wrote: > On Thu, Feb 20, 2020 at 02:19:13PM -0800, Stephan Hoyer wrote: > > > > > Strong +1 for an array.zeros() constructor, and/or a lower level > > > array.empty() which doesn't pre-fill values. > > > > > > So it'd be a shorthand for something

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-21 Thread Serhiy Storchaka
21.02.20 10:36, Steven D'Aprano пише: On my machine, at least, constructing a bytes object first followed by an array is significantly faster than the alternative: [steve@ando cpython]$ ./python -m timeit -s "from array import array" "array('i', bytes(50))" 100 loops, best of 5: 1.71 msec

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-21 Thread Andrew Barnert via Python-ideas
On Feb 21, 2020, at 00:46, Steven D'Aprano wrote: > > > Got some actual measurements to demonstrate that initialising the array > is a bottleneck? Especially for something as small as 64, it seems > unlikely. If it were 64MB, that might be another story. > > What's wrong with

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-21 Thread Steven D'Aprano
On Thu, Feb 20, 2020 at 02:19:13PM -0800, Stephan Hoyer wrote: > > > Strong +1 for an array.zeros() constructor, and/or a lower level > > array.empty() which doesn't pre-fill values. > > > > So it'd be a shorthand for something like this? > > > > >>> array.array("i", bytes(64)) > > array('i', [0,

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Christopher Barker
On Thu, Feb 20, 2020 at 12:43 PM Steve Jorgensen wrote: > > > But frankly, it would be a rare case where this would be noticeable. > > -CHB > > Maybe uncommon, but I don't know about rare. Let's say you want to perform > list-wise computations, making new lists with results of operations on >

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Stephan Hoyer
On Thu, Feb 20, 2020 at 2:11 PM Chris Angelico wrote: > On Fri, Feb 21, 2020 at 8:52 AM Stephan Hoyer wrote: > > > > On Thu, Feb 20, 2020 at 12:41 PM Steve Jorgensen > wrote: > >> > >> Christopher Barker wrote: > >> ... > >> > > Perhaps the OP wanted the internal array size initialized, but

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Chris Angelico
On Fri, Feb 21, 2020 at 8:52 AM Stephan Hoyer wrote: > > On Thu, Feb 20, 2020 at 12:41 PM Steve Jorgensen wrote: >> >> Christopher Barker wrote: >> ... >> > > Perhaps the OP wanted the internal array size initialized, but not used. >> > Currently the internal array will automatically be

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Stephan Hoyer
On Thu, Feb 20, 2020 at 12:41 PM Steve Jorgensen wrote: > Christopher Barker wrote: > ... > > > Perhaps the OP wanted the internal array size initialized, but not > used. > > Currently the internal array will automatically be reallocated to grow as > > needed. Which could be a performance hit if

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Steve Jorgensen
Christopher Barker wrote: ... > > Perhaps the OP wanted the internal array size initialized, but not used. > Currently the internal array will automatically be reallocated to grow as > needed. Which could be a performance hit if you know it’s going to grow > large. > But frankly, it would be a

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Christopher Barker
On Thu, Feb 20, 2020 at 7:34 AM Serhiy Storchaka wrote: > 20.07.11 23:48, Sven Rahmann пише: > > What's missing is the possiblity to specify the final size of the > > array (number of items), especially for large arrays. > > array.array(typecode, [fillvalue]) * n Perhaps the OP wanted the

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Serhiy Storchaka
20.07.11 23:48, Sven Rahmann пише: At the moment, the array module of the standard library allows to create arrays of different numeric types and to initialize them from an iterable (eg, another array). What's missing is the possiblity to specify the final size of the array (number of items),

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Steve Jorgensen
I discovered that same trick. It would be nice to have that specifically indicated in the documentation until/unless a length argument is added to the constructor. It would be nice for the supported operators to be documented at all, actually. I didn't realize that array.array had