2 ms·
Consider a program written in Python. Imagine it converted into some "internal representation" that will be used by the interpreter to execute it. We can ask q
by PaulDavisThe1st 7y ago
Consider a program written in Python. Imagine it converted into some "internal representation" that will be used by the interpreter to execute it.
We can ask questions like "when I write a statement in Python that adds two integers (typically a single machine instruction in a C program), how many machine instructions are executed while running that statement?"
Those are questions about the interpreter - essentially, the raw speed and execution patterns of the language.
But when you're running a Python program (or one written in many other languages these days), there is a lot going on inside the process that you cannot map back to the Python statements you wrote. The most obvious is memory management, but there are several others.
This stuff takes time to execute and can change the behavior of the statements that you did write in subtle (and not so subtle ways).
Note that this kind of issue exists even for compiled languages too: when you run a program written in C++, the compiler will have inserted varying amounts of code to manage a variety of things into the executable that do not map back explicitly to the lines you wrote. This is the "C++ runtime" at work, and even though the "C++ language" may run at essentially machine speed, the runtime still adds overhead in some places.
Interpreted languages are the same, just worse (by various metrics)
- throwaway894345 7y agoI understand the notion of a "runtime" in the compiled language case; my question is about the distinction between an interpreter and a runtime in the interpreted language case. Perhaps out of naivety, I would think that the interpreter is the runtime--the interpreter manages the call stack, memory, etc.
- PaulDavisThe1st 7y agoWell, imagine for example that you wrote this in python: s = "hello" + "world" You could measure the execution of the internal representation of this, and that would be all about the speed of the interpreter. At some point, something may have to clean up temporaries and that may happen asynchronously with respect to the actual statement execution. Yes, it happens in the same process as the interpreter's execution of the code, but it's a theoretically "optional" cost that has no specific relationship with the statement. There are interpreters, for example, where you can disable garbage collection. If the overall execution time decreased, it's not because the interpreter got faster, it's just doing less of the "runtime" work.
- throwaway894345 7y agoSo is there anything besides the GC which satisfies this definition of "runtime"? What other asynchronous activities are going on apart from those of the Python program itself?