|
|
|
|
|
by glofish
2373 days ago
|
|
Is 5 seconds such a long time really? For parsing a file, then creating and evaluating 1 million local variables, all inserted into the local namespace? Made me wonder, how long does it take to compile a million line long C program? Let's see: N = int(1E6)
print("""#include <stdio.h>
int main() {
""")
for x in range(N):
print (f"int x{x}={x};")
print("""
return 0;
}
""")
now generate the code and compile it: time gcc big.c
drumroll ... ummm ... look at that ... doesnt finish, hangs forever (or at least longer that care to stick around wich was 10 minutes) ...notably for 10,000 variables it takes just 0.3 seconds, but raising that number one order of magnitude to 100,000 makes it hang, 100% CPU 3% memory used. Something has an awful scaling behind the scenes. |
|
Compilation is technically NP-Hard, meaning it scales very poorly, as you described, whereas interpretation is not (no register allocation, etc).
https://cs.stackexchange.com/questions/22435/time-complexity...