Technically speaking, interpreted languages aren’t compiled at all. That was the original definition.
Nowadays, there’s hardly any clasically interpreted language. All major interpreted languages compile to bytecode, which is then run via a kind of VM that interprets that language. But many languages (like Java) go even farther and compile that bytecode into native machine code at runtime.
Being interpreted, though, is an implementation feature, not a language feature. So, for example, if you use CPython, Python is compiled into bytecode when you first run a script. The bytecode is then stored and used the next time you run the same script as long as it hasn’t been changed in the meantime. You can also force the compilation to bytecode and only ship the bytecode.
But if you use Pypy instead of CPython, it is a regular compiler that compiles into native machine code. No bytecode and/or interpretation in the process at all. This increases the performance of pure Python by around 5x, according to some benchmarks.
But that kind of benchmarking is kinda flawed anyway because most real-life programs don’t only use pure Python.
There’s a thing called Cython (not to be confused with the Python interpreter called CPython), which allows C-Code to be called from Python. Cython is used by almost all modules that contain performance-critical code, and it’s just as fast as using C directly.
In most applications, you have a concept called “hot code”. That’s specific code paths that take up the vast majority of the code execution time (usually 95+% of the time are spent on just a few code paths). So when optimizing Python code, you figure out which these are and then you use Cython to implement them in C (or use a 3rd party module that already does that).
Then you use Python only as a “glue code” that covers all the low-usage code.
In that use case, Python is only marginally slower than C.
Slow Python programs are usually an issue of optimization, not an issue of the language itself.
Jarix@lemmy.world 2 days ago
Love you. Thank you
DarkAri@lemmy.blahaj.zone 2 days ago
Interpreted languages are very optimized these days, and get much closer to native C performance.
Also thanks internet stranger. <3