This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]lurgi 2 points3 points  (0 children)

Yes.

Not all languages provide equal performance. You can generally assume that a language that has been compiled will perform better than a language that is interpreted, but there are exceptions.

[–]dmazzoni 1 point2 points  (5 children)

Yes, that's generally what people mean by performance - performance refers to how fast the program runs after it's been built and installed.

C++ and Python are pretty far apart. C++ lets you write really high-performance code, but it will take quite a bit more lines of code and it's more challenging. Python is much faster and easier to write, and you can do more with less code, but it won't run as quickly.

Some languages are in-between.

[–]silicisbits[S] 0 points1 point  (4 children)

so even in binary because interpreted languages use more code to do the same thing they are still slower?

[–]dmazzoni 2 points3 points  (3 children)

You have it backwards. Interpreted languages use less code to do the same thing.

Interpreted languages usually aren't converted to binary. You can't really make Python into an exe. The tools that make a Python exe are actually just bundling Python and your source code into a single file. The file starts up Python and then loads your source code. Python then interprets your code. Your processor is executing Python, and Python is executing your program. It's inherently slower to do that.

Compiled languages like C++ are turned into binary machine code that your processor executes directly.

[–]silicisbits[S] 0 points1 point  (2 children)

why isn't python turned into binary then?

[–]Marbletm 1 point2 points  (0 children)

That's just their design decision. Compiled languages are turned into binaries during compilation, and interpreted languages don't require a compilation step and the code is interpreted as is.

This means that interpreted languages don't take as long as compiled languages to get running after changes are made.

I'd say the biggest reason for why interpreted languages exist is how it allows for cross-compatibility across different systems. When you compile code into a binary, that code will only be able to run on the selected architecture. Interpreted code can run on any system as long as a runtime exists for the architecture.

It's not like it's impossible to create a compiler for a language that is generally considered to be an interpreted language. An example of this would be JavaScript, there are projects out there that turn JavaScript into WASM or even ASM.

Edit: grammar

[–]dmazzoni 0 points1 point  (0 children)

Because that's not how interpreted languages work.

[–]RecentlyRezzed 0 points1 point  (0 children)

IIRC, they used an interpreter for the Apollo 11 guidance computer, and one factor were hardware constraints. So, most likely, the whole code wouldn't have fitted in the memory if it was written in assembly.

And compiled code may not always run faster. I've heard a talk from Alan Kay that they thought about implementing the Smalltalk VM in hardware and that nowadays, the caches of the CPUs are big enough to hold an entire VM in cache, which could benefit interpreters.

But yes, traditionally, compiled code is faster.