[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Python list micro-benchmarks
From: |
Bruno Haible |
Subject: |
Re: Python list micro-benchmarks |
Date: |
Mon, 08 Apr 2024 16:23:41 +0200 |
Hi Collin,
> I think that I see the issue here. I believe this is a case of the
> "prior knowledge summarization engine" being incorrect. Given this
> statement:
>
> a += [var]
>
> it seems to think that a new copy of 'a' is being created. This is
> incorrect. The given statement is equal to:
>
> operator.iadd(a, [var])
>
> The Python documentation states that "For mutable targets such as
> lists and dictionaries, the in-place method will perform the update,
> so no subsequent assignment is necessary [2]."
OK, that explains it:
- It explains why the '+= [item]' was nearly constant-time even on a
list of length 1000.
- It explains ChatGPT's failure: Probably there are more explanations
regarding += on strings, on the web, than regarding += on lists.
So ChatGPT used the "common" explanation, for strings, and then
substituted s/string/list/.
Thanks. Now I agree to converging on .append(..), because by my common
measure "what is surprising to a naïve developer?" the '+= [item]'
syntax has two negative scores:
- It's surprising that += is optimized differently than +.
- It's surprising that lists are optimized differently than strings.
Bruno
- Re: gnulib-tool.py: Fix 'consider-using-with' pylint warnings., (continued)
- Re: gnulib-tool.py: Fix 'consider-using-with' pylint warnings., Bruno Haible, 2024/04/05
- Re: gnulib-tool.py: Fix 'consider-using-with' pylint warnings., Collin Funk, 2024/04/05
- Re: gnulib-tool.py: lists vs. sets, Bruno Haible, 2024/04/06
- Re: gnulib-tool.py: lists vs. sets, Collin Funk, 2024/04/06
- Re: gnulib-tool.py: lists vs. sets, Bruno Haible, 2024/04/07
- Re: gnulib-tool.py: lists vs. sets, Collin Funk, 2024/04/07
- Re: Python list micro-benchmarks, Bruno Haible, 2024/04/07
- Re: Python list micro-benchmarks, Collin Funk, 2024/04/07
- Re: Python list micro-benchmarks, Paul Eggert, 2024/04/07
- Re: Python list micro-benchmarks, Collin Funk, 2024/04/07
- Re: Python list micro-benchmarks,
Bruno Haible <=
- Re: Python list micro-benchmarks, Collin Funk, 2024/04/08
- Re: Python list micro-benchmarks, Bruno Haible, 2024/04/08
- Re: Python list micro-benchmarks, Paul Eggert, 2024/04/08
- Re: Python list micro-benchmarks, Collin Funk, 2024/04/08
- gnulib-tool.py: Prefer 'list.append(item)' over 'list += [item]'., Collin Funk, 2024/04/08
- Re: gnulib-tool.py: Prefer 'list.append(item)' over 'list += [item]'., Bruno Haible, 2024/04/08
- Re: gnulib-tool.py: Prefer 'list.append(item)' over 'list += [item]'., Collin Funk, 2024/04/08