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. 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 <[email protected]> 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 -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/[email protected]/message/CCZG6ALFEV3B67LENW5ZDJG5XSHKREG4/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/KUNHKJJJTSXNSJRBTGZNIA2TGYM5OE7O/ Code of Conduct: http://python.org/psf/codeofconduct/
