Table of contents
A JIT (Just-In-Time) compiler is a type of compiler that dynamically translates and compiles sections of code at runtime, typically during the execution of a computer program.
You have already used it because when you open a browser you run a Just in Time javascript compiler.
Working
JIT starts a program running an interpreter and looks at it for things like functions which is called a lot and let's say some function taking parameters that are always integers or strings (same type) so It will produce an optimized version of that functional part based on the information it has observed.
It's that dynamic analysis and conversion into machine code at runtime that makes JIT effective.
Setting up in Pyhton
You can set it up using conda
or if you want to look for some other methods you can have a look here https://doc.pypy.org/en/latest/install.html
conda create -c conda-forge -n my_cool_pypy pypy python=3.9
conda activate my_cool_pypy
conda install scipy
Example
def add(x, y):
return x + y
print(add(2,3))
a = 0
for _ in range(10000000):
a += add(2,3)
To run without JIT
time pypy --jit off add.py
To run with JIT
time pypy add.py
Comparison with and without JIT
That's all to learn more about it you can check the official documentation of Pypy here:
https://doc.pypy.org/en/latest/index.html