xordux's blog

By xordux, history, 4 years ago, In English

I always saw Python(CPython) as inferior to PyPy3, because of SPEED

but today while working on a easy problem(189A - Cut Ribbon) I found that I was getting repeated Runtime Errors. I tried to improve my code but my solution didn't got Accepted.

My (Runtime error) PyPy3 solution: https://mirror.codeforces.com/contest/189/submission/86150951

after struggling for sometime, I thought I should give Python(CPython3) a try and submitted the same code in Python3. Voila!! I got AC immediately.

My (Accepted) Python3 solution: https://mirror.codeforces.com/contest/189/submission/86150968

What was I doing wrong? I don't know clearly for now, but I can see that there is a huge difference in memory consumption of Python3(8952 KB) and PyPy3(24604 KB). Maybe my solution was taking too much memory in PyPy3 and that's why it got Runtime error.

I googled about it for few minutes and found a wonderful article explaining why PyPy3 consumes lot of memory: https://morepypy.blogspot.com/2013/10/incremental-garbage-collector-in-pypy.html

This article basically says: The main reason why PyPy is faster than CPython is that PyPy delays garbage collection. Please correct me if I am wrong.

I will try to replicate this in my local system and see what's happening. If get any new info, then I will add it here.

TLDR; Try Python when you are getting error with PyPy

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it