I'm very well aware of this. The reason why I'm interested in the speed of .insert is that I've been trying to do a very fast implementation of insert sort. My idea is that if the number of elements I'm trying to sort are few (say <= 256), then I should be able to use array.array('B') to speed up the insert step by a factor of 8 compared to doing it with a list.

The reason why a fast running insert sort is super useful in Python is because there is a fascinating data structure called SortedList. This data structure uses insert sort on chunks (of size ~1000) as a subrutine, and it runs faster than any treap/AVL-tree/rbtree implementation that I've ever tried.

I have for a long time been playing around with implementing my own version of the sorted list data structure, and my hope was that I could use array.array('H') to make my version run up to 4 times faster. But when I benchmarked using array, I noticed that it ran really fast in CPython, and really sluggish in PyPy.

array.array insert(0,x) runs really sluggish in PyPy. PyPy can be slower by a factor of 13 compared to CPython. For example, on my windows computer running this program

```
import array
if 2/3: # Python3 vs Python2 check
from time import perf_counter as timer
else:
from time import clock as timer
for A in [], array.array('H'), array.array('B'):
l = timer()
for x in range(10**5):
A.insert(0, x % 100)
r = timer()
print('Took %f seconds' % (r - l))
```

I get the following output:

CPython 3.9.5 (64 bit)

```
Took 1.095486 seconds
Took 0.158121 seconds
Took 0.081960 seconds
```

CPython 2.7.18 (64 bit)

```
Took 1.103622 seconds
Took 0.261555 seconds
Took 0.139270 seconds
```

PyPy3 7.3.4 (64 bit)

```
Took 0.626467 seconds
Took 1.049843 seconds
Took 1.051765 seconds
```

PyPy2 7.3.4 (64 bit)

```
Took 0.628617 seconds
Took 2.114030 seconds
Took 1.054899 seconds
```

Thanks!

This basic Python program will segfault when run in either PyPy2 or PyPy3.

```
def gcd(x, y):
while y:
x, y = y, x % y
return x
def main():
n = 50
a = list(range(1, n + 1))[::-1]
f = [0] * n
f[0] = 1
g = a[0]
for i in range(n):
mx = 0
pos = -1
for i in range(n):
if f[i] == 0:
if gcd(g, a[i]) > mx:
mx = gcd(g, a[i])
pos = i
g = gcd(g, a[pos])
main()
```

I've tested this locally on my Windows computers (running PyPy2 and PyPy3 7.3.1) and I've also had multiple friends try running it on their systems. It segfaults for everyone.

Worth noting is that adding the line `pypyjit.set_param(threshold = 2)`

at the top will make it segfault for n = 3. So the segfault seems to be connected to the JIT.

So is this a bug in PyPy? I thought that setrecursionlimit(N) in PyPy was supposed to `Setting the value to N reserves N/1000 times 768KB of stack space.`

making it so you can do deeper recursion.

Ah yes, 32 bit CPython actually does segfault too. Don't know how I didn't notice that. Sorry

CPython never segfaults, it seems to be Windows PyPy specific.

This simple program segfaults at the `f(5000)`

call (when using Windows)

```
import sys
sys.setrecursionlimit(10**5)
def f(x):
if x:
f(x - 1)
f(5000)
print('Done')
```

It never prints `Done`

.

I've tested this on the latest versions of PyPy2 and PyPy3 running the program locally on both of my Windows computers and everything segfaults. I've also tried running it on codeforces.com (which runs Windows) and it segfaults there too.

The smallest `x`

for which `f(x)`

segfaults seems to vary depending on the system, but `f(5000)`

has segfaulted on every computer I've tested it on so far.