> the code needs to be ported to work under PyPy.
The only incompatibility is the `.copy()` calls which should be replaced by `list(contents)`, then it'll be cross-compatible between P2 and P3.
Here's what I get with that (on a 2010 MBP) using the random generation of lgas above (1M random ints):
> time python2.7 qs.py
python2.7 qs.py 41.92s user 0.37s system 98% cpu 42.837 total
> time python3.6 qs.py
python3.6 qs.py 42.99s user 0.32s system 98% cpu 44.047 total
> time pypy qs.py
pypy qs.py 3.27s user 0.12s system 94% cpu 3.603 total
There's a fair bit of variation but pypy is between 3.4 and 4
The real comparison should be a language that is both functional and imperative and that allows you to write as brief a source code as you can do in Haskell.
Such a language is Common Lisp, and it will compile directly to machine language doing many optimizations.