Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between Go and Cython [closed]

Tags:

python

go

cython

Today a great friend of mine asked me what are the main differences between the newest Go language and Cython, which is a set of C-extensions for Python. I don't have much knowledge on Python, can anyone tell me why Go is better/worse than Cython?

like image 362
Miguel Rentes Avatar asked Nov 16 '09 17:11

Miguel Rentes


People also ask

What is the difference between CPython and Cython?

CPython is the implementation of the language called “Python” in C. Python is an interpreted programming language. Hence, Python programmers need interpreters to convert Python code into machine code. Whereas Cython is a compiled programming language.

Why Cython is not popular?

Learning curve is not very steep among other options. There is easy parallelism when you need it. And you dont have to choose either python or C, can use both at the same time (sort of) ! It surprises me that its usage is very limited.

Does Cython improve performance?

The CPython + Cython implementation is the fastest; it is 44 times faster than the CPython implementation. This is an impressive speed improvement, especially considering that the Cython code is very close to the original Python code in its design.

Is Cython as fast as C?

Cython code runs fastest when “pure C” But if that function references any Python-native code, like a Python data structure or a call to an internal Python API, that call will be a performance bottleneck.


2 Answers

Cython isn't really a language in the conventional sense. It is a preprocessor for building Python extensions that takes Python-like syntax (actually they strive for full Python compatibility) and produces C code (using the Python C API). Doing this they are able to include some special case optimisations, but the real benefits come when you add Cython specific static type information which is incorporated into the C code, bypassing the Python runtime for those operations and resulting in a high speed up.

Go is a compiled programming language. The first thing that can be done in Go is producing an executable that doesn't include the Python runtime/start a Python interpreter - this is impossible in Cython. (May not be technically impossible - but there is really no point to use Cython if you are not working with Python). Since Cython just produces C most of your questions in the comment don't really apply - you can use any C debugger (although the fact that's a Python extension makes things a bit more complicated).

like image 51
robince Avatar answered Sep 20 '22 02:09

robince


gevent is a concurrent library that uses Cython at its core. It seems to be pretty fast: http://nichol.as/asynchronous-servers-in-python

like image 35
Ben Ford Avatar answered Sep 20 '22 02:09

Ben Ford