On Wed, Dec 21, 2022 at 8:34 AM Jeremiah Paige <ucod...@gmail.com> 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 having myvar be precomputed as the single tuple > also > gives speedups, around 45% for me. > That may be the optimization that 3.11 is doing for you :-) Now that I think about it, if this is immutable, which it should be, as it's a str subclass, then perhaps the data string can be pre-computed, as it was in the original. I liked the property, as philosophically, you don't want to store the same data twice, but with an immutable, there should be no danger of it getting out of sync, and it would be faster. (though memory intensive for large strings). -CHB > So if just speed is wanted maybe inject the > tuple pre-constructed. > > ~ Jeremiah > > On Wed, Dec 21, 2022 at 1:19 AM Steven D'Aprano <st...@pearwood.info> > 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): >> return "".join((self,)) >> >> That's about 14% faster than the f-string version. >> >> _______________________________________________ >> Python-ideas mailing list -- python-ideas@python.org >> To unsubscribe send an email to python-ideas-le...@python.org >> https://mail.python.org/mailman3/lists/python-ideas.python.org/ >> Message archived at >> https://mail.python.org/archives/list/python-ideas@python.org/message/CCZG6ALFEV3B67LENW5ZDJG5XSHKREG4/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/KUNHKJJJTSXNSJRBTGZNIA2TGYM5OE7O/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/FUZ6H6OY4JIJ4CSUUGLDHMILZWU7VXGE/ Code of Conduct: http://python.org/psf/codeofconduct/