Re: Python list micro-benchmarks

2024-04-08 Thread Collin Funk
On 4/8/24 3:36 PM, Paul Eggert wrote: > For what it's worth, the business about the cost of x.append(y) (it's > O(len(x)), and O(1) amortized) has been a standard part of the cost model > lecture in my programming languages course for more than two decades, so I > hope that UCLA graduates, at le

Re: Python list micro-benchmarks

2024-04-08 Thread Paul Eggert
On 4/8/24 14:19, Bruno Haible wrote: My experience is that ChatGPT (3.5) provides good answers for things that have a lot of mentions on the web. Whereas for things that are rarely mentioned, it starts to hallucinate and often provides wrong answers. Therefore, for routine questions around Python

Re: Python list micro-benchmarks

2024-04-08 Thread Bruno Haible
Hi Collin, > > - 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/. > > Interesting. I know very

Re: Python list micro-benchmarks

2024-04-08 Thread Collin Funk
On 4/8/24 7:23 AM, Bruno Haible wrote: > - 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/. Interestin

Re: Python list micro-benchmarks

2024-04-08 Thread Bruno Haible
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

Re: Python list micro-benchmarks

2024-04-07 Thread Collin Funk
Hi Paul, On 4/7/24 5:51 PM, Paul Eggert wrote: > a.append should be faster, as it need not cons the singleton. Thanks. Yes, that it is what I was trying to get at. But I didn't know the correct wording. :) Here is 'var.extend(["a"])' added to the simple timeit comparison: >>> import timeit >>>

Re: Python list micro-benchmarks

2024-04-07 Thread Paul Eggert
On 2024-04-07 16:07, Collin Funk wrote: I think that the difference between 'a.extend([var])' and 'a.append(var)' would better explain the differences in timing that we see with a large number of repetitions. a.append should be faster, as it need not cons the singleton.

Re: Python list micro-benchmarks

2024-04-07 Thread Collin Funk
Hi Bruno, On 4/7/24 7:23 AM, Bruno Haible wrote: > I like the first one a little more. So I asked the prior knowledge > summarization engine (ChatGPT): I like that description, "prior knowledge summarization engine". > Since you show me how to do benchmarks, and since ChatGPT warns about large >

Re: Python list micro-benchmarks

2024-04-07 Thread Bruno Haible
Collin Funk wrote: > That reminds me, is there a reason why in many places there is > something like this: > > newtail = [] > for item in tail: > newtail += [item] > > instead of this? > > newtail = [] > for item in tail: > newtail.append(item) > > I like t