On Tue, Dec 20, 2022 at 11:55:49PM -0800, Jeremiah Paige wrote:
> @property
> def data(self):
> return f"{self}"
By my testing, on Python 3.10, this is slightly faster still:
@property
def data(self):
return "".join((self,))
That's about 14% faster than the f-stri
That's interesting, for me both 3.9 and 3.10 show the f-string more than 5x
faster.
This is just timeit on f'{myvar}' vs ''.join((myvar,)) so it may not be the
most nuanced
comparison for a class property.
Probably unsurprisingly having myvar be precomputed as the single tuple also
gives speedups,
On Wed, Dec 21, 2022 at 1:18 AM Steven D'Aprano wrote:
> On Tue, Dec 20, 2022 at 11:55:49PM -0800, Jeremiah Paige wrote:
> > @property
> > def data(self):
> > return f"{self}"
>
> By my testing, on Python 3.10, this is slightly faster still:
>
> @property
> def data(self):
On Wed, Dec 21, 2022 at 8:34 AM Jeremiah Paige wrote:
> That's interesting, for me both 3.9 and 3.10 show the f-string more than
> 5x faster.
> This is just timeit on f'{myvar}' vs ''.join((myvar,)) so it may not be
> the most nuanced
> comparison for a class property.
> Probably unsurprisingly h
On Thu, 22 Dec 2022 at 03:41, Christopher Barker wrote:
>
> On Wed, Dec 21, 2022 at 1:18 AM Steven D'Aprano wrote:
>>
>> On Tue, Dec 20, 2022 at 11:55:49PM -0800, Jeremiah Paige wrote:
>> > @property
>> > def data(self):
>> > return f"{self}"
>>
>> By my testing, on Python 3.10, t
On Wed, Dec 21, 2022 at 8:54 AM Chris Angelico wrote:
> > I think both of those will call self.__str__, which creates a recursion
> -- that's what I'm trying to avoid.
> >
> > I'm sure there are ways to optimize this -- but only worth doing if it's
> worth doing at all :-)
> >
>
> Second one does
On Thu, 22 Dec 2022 at 04:14, Christopher Barker wrote:
>
> On Wed, Dec 21, 2022 at 8:54 AM Chris Angelico wrote:
>>
>> > I think both of those will call self.__str__, which creates a recursion --
>> > that's what I'm trying to avoid.
>> >
>> > I'm sure there are ways to optimize this -- but onl
On Tue, Dec 20, 2022 at 11:17 PM Stephen J. Turnbull <
stephenjturnb...@gmail.com> wrote:
> Ricky Teachey writes:
>
> > This isn't to say it should definitely be added to the language, that's
> a
> > tough hurdle. But boy would I have used it.
>
> IIUC, Mathew's idea doesn't need to be added to
On Wed, Dec 21, 2022 at 9:35 AM Chris Angelico wrote:
> From the look of things, PyUnicode_Join (the internal function that
> handles str.join()) uses a lot of "reaching into the data structure"
> operations for efficiency. It uses PyUnicode_Check (aka "isinstance(x,
> str)") rather than PyUnicod