On Wed, Jul 8, 2020 at 7:13 PM Inada Naoki <songofacandy@gmail.com> wrote:
I think this comparison is unfair.
well, benchmarks always lie ....
d.items()[0] vs list(d.items())[0]
Should be compared with `next(iter(d.items())`
why? the entire point of this idea is to have indexing syntax -- we can already use the iteration protocol top do this. Not that it's a bad idea to time that too, but since under the hood it's doing the same or less work, I'm not sure what the point is.
d.keys()[-1] vs list(d.keys())[-1]
Should be compared with `next(reversed(d.keys()))`, or `next(reversed(d))`.
Same point - the idea is to have indexing syntax. Though yes, it would be good to see how it compares. But I know predicting performance is usually wrong, but this is going to require a full traversal of the underlying keys in either case.
random.choice(d.items()) vs random.choice(list(d.items()))
Should be compared with `random.choice(items_list)` with `items_list = list(d.items())` setup too.
I don't follow this one -- could you explain? what is items_list ? But what this didn't check is how bad the performance could be for what I expect would be a bad performance case -- indexing teh keys repeatedly: for i in lots_of_indexes: a_dict.keys[i] vs: keys_list = list(a_dict.keys) for it in lots_of_indexes: keys_list[i] I suspect it wouldn't take all that many indexes for making a list a better option. But again, we are badk to use cases. As Stephen pointed out no one has produced an actualy production code use case. I myself have wanted this (the random.choice option) -- but it wasn't production code it was a learning exercise, specifically: http://codekata.com/kata/kata14-tom-swift-under-the-milkwood/ I can imagine there would be that use case in real world code, but I haven't had it. -CHB
-- Inada Naoki <songofacandy@gmail.com> _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/73YTQD... Code of Conduct: http://python.org/psf/codeofconduct/
-- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython