Why are certain languages faster than others?

Asked

Viewed 404 times

7

I’ve heard a lot about how C is faster than C++ and Java, Lua is the language of script faster, among other examples.

What makes certain languages faster than others? What defines a language as "fast"? For example, speed of execution of an instruction, speed at which the program runs, among others.

1 answer

11


I’ve heard a lot about how C is faster than C++ and Java, Lua is the fastest scripting language, among other examples.

Languages are not faster

It’s not like that, languages are not fast or slow, they may have more ability to facilitate some things to be executed faster or not. Even in some operations a language can do better and in others go worse when compared to another language.

There are language implementations that can be faster or slower.

Often the difference is even in the library used by the language and not in itself.

Comparisons

It is not for C to be faster than C++, in general. Whoever speaks this should explain why this would happen. There are several cases where C++ can be faster within the standard.

Much of the fact that compilers of these languages generate code better is the culture of doing this.

There are cases that depends on how you do it, you may be able to do it faster but the price you pay for it is too high too. It’s not hard to see some C# codes run faster than C++ (today even easier), but if there is a good effort to improve the C++ code he can beat the C#. It’s not C++ that’s faster, it’s the culture around it that produces fast codes.

It has certain memory usage patterns (very common) that makes the tracing GC be faster than simple GC or common manual management and only very careful and laborious management can beat what the . NET or JVM can.

Not to mention that there are very different implementations than people are used to, for example have C interpreted that is very slow.

Script

Of course languages whose implementation depends on interpretation or a virtual machine to run will be slower, at least to some extent, there is an extra process to be carried out in the execution. But it is still a question of implementation, because every language could be implemented in one way or another, unless the specification determines or prohibits some form.

Lua is fast because it has a very efficient and simple virtual machine (simplicity is the secret, so the software industry has gone down a bad road). Of course the language was designed not to require a very complex VM.

Jitter

In some cases having someone interested in doing something good helps, Lua is fast on the pattern, but it’s even more so with Luajit because there was a guy very good at it interested in making a Jitter. As he is no longer in the project, there is no evolution that could have.

Today I think it’s easy to say that Javascript is the language of script faster once it starts (Jitter costs a little high), precisely because there are big suppliers interested that it runs very fast. It can, though difficult, run some cases faster than C by having a chance to adapt during execution (I don’t know if anyone did this).

Abstractions that help or disturb

Of course some languages have constructs that hide processing cost, mainly from the naive programmer, so it’s not that it’s slower, it’s giving you some ease that has a cost, and in some cases you pay even if you don’t need.

C++ is a language that has these abstractions at no cost or only pays if you need to. So if you need to have a cost equal to C, the best because there are cases that can better express the intention giving more opportunity for optimization.

C has a problem with its flexibility. By letting do much the compiler has to be more careful when optimizing.

What makes certain languages faster than others? What defines a language as "fast"? (for example, speed of execution of an instruction, speed at which the program runs, among others)

Nothing defines a language as fast, this is a misconception. As much as we can say that the language, its library, the current implementations and the culture of users of a given language usually produce applications that are faster or more efficient (which is better than being fast, because being fast is almost ambiguous and naive).

Instruction execution speed is determined by the processor and not by the language.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.