D
D
Daniel2018-03-14 11:18:16
Java
Daniel, 2018-03-14 11:18:16

Can a language be faster than the language in which its compiler is written?

For example, I am writing a simple language compiler that will only output hello world, can it work and will it be faster than metalanguage hello world?
As I understand it, if I write a compiler in c ++, then it will be faster, since I will have a binary . And if I write it in Java, then maybe it is faster than Java itself, because in the end, you need to add a huge code of the translator itself to the small code of the written program. And then he will work for any longer. And if I reason correctly, then I cannot understand why there are not a small number of well-known compilers for different Java languages ​​in java, because the result of the program on them will be slower.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pfg21, 2018-03-14
@pfg21

it all depends not on the language in which you write, but on the efficiency of the generated binary code.
if the compiler generates good and high-quality code, then the speed will naturally be good, regardless of the speed of generating the on-line executable code.
usually, on the contrary, by the way, if you enable all options for optimizing the speed of execution in the compiler, then compilation will take longer due to deeper analysis
, and it depends very much on the qualities of the scribbler, even languages ​​\u200b\u200bdo not help here.
I remember at the university a long time ago there was a lab in which it was necessary to manually write a script in assembler, hand it over to "compile" it into binary code, enter it into a training microprocessor kit for 580vm80, and achieve efficiency.
as you understand, the speed of manual compilation into executable code was terribly slow, but the execution time did not suffer from this ...

S
Sergey, 2018-03-14
@red-barbarian

actually
1. java runs on a java machine (in short). C++ on processor
2. It is far from a fact that a C++ program written by a beginner will be faster than Java written by a beginner. (the matter is that many things in libraries are optimized.). The same applies to scripting languages ​​such as python (for example, with a library like numpy)
Total:
the speed of work depends on:
- the type of executable file (this is a binary for a specific processor and system, this is a file that is executed on a virtual machine, this is a script)
- optimization code, libraries, interpreter, virtual machine.
More philosophy.
The root of all evil is early optimization. quote
Those. you need to optimize only what really affects the speed. Narrow places. just chasing speed is not right.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question