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.
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:
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)
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.
/usr/bin/python
That is, actual execution: more than 6 seconds. 😞
codon
Actual execution: in less than 1 second!!! 😲