Codon, a Python Compiler written with C++ and LLVM
High performance and no overhead! In a test I did, the performance gain was greater than 600%.
Codon is a high-performance Python compiler that compiles Python code to native machine code without any runtime overhead.
The compiler was written with C++ and uses LLVM as the final assembly code optimizer. Unlike Python, Codon supports native multithreading, which can lead to even greater speedups.
Installation
You can compile Codon on your own machine, however there are precompiled binaries for Linux and macOS.
In the case of Linux just run this command below:
You must have cURL installed.
At the end of the installation it will ask you to confirm the addition of the binary to your $PATH
variable, press y
for yes. If it doesn’t work, even opening it in a new terminal, as he advises, run the following commands:
To test run:
Usage
Suppose you have this code Python which is a Fibonacci function, you can interpret the code with Codon itself:
To run without compiling:
However, the performance will not be very good. The correct thing is to compile this code to a binary and then run the binary, example:
You can still compile with [LLVM] optimization(https://terminalroot.com/tags#llvm)
Analyzing the performance
When we used a for loop
with 1 million cycles in Python, as we did in this video, Codon was about 600% faster than native interpreter (version 3.10.9
).
Test file/code can be obtained here.
Result using /usr/bin/python
That is, actual execution: more than 6 seconds. 😞
Result using codon
Actual execution: in less than 1 second!!! 😲
Comments