1

Machine code is particularly depended on the machine on which it is executed. This means that efficiency machine code depend upon machine. But, if we talk about the efficiency of assembly level and high level languages than assembly languages are more efficient in execution than high level because assembly uses mnemonic codes or symbols which are more closer to machine code.

above answer is correct or not?

Manjeet Singh
  • 57
  • 1
  • 6
  • No. Compilers today are made to optimize the code extremely well. In most cases the compiler can optimize better than most human programmers. – NomadMaker Sep 01 '20 at 05:25
  • @NomadMaker What would be the correct answer? – Manjeet Singh Sep 01 '20 at 07:50
  • In most cases, a good solution written in a high-level language will be more efficient than something written in assembly code. This is because compilers today are very good at optimization. – NomadMaker Sep 01 '20 at 08:05
  • my question is about machine code . Means which machine is better or more efficient one obtain from high level language or second obtain from assembly language . – Manjeet Singh Sep 01 '20 at 08:06
  • You would need to define which machines to make the comparison. I still stand by my statement that a good compiler will produce faster code than most programmers could write in assembly. – NomadMaker Sep 01 '20 at 08:09
  • @NomadMaker as far as I understand, his questions is more about what will perform better: machine code generated out of high level language such as C++ or machine code generated out of interim code such as a byte code (java's middle layer). My opinion here that there is no difference, and only compiler's quality matters. – Alexander Makarov Sep 01 '20 at 08:38
  • @AlexanderMakarov If that is the question, then I would say that most of the studies I've seen have shown that C/C++ can beat the JVM languages by a small amount. However, I'm mainly a Java programmer and do not want to give up the advantages of Java for small speed improvements. – NomadMaker Sep 01 '20 at 08:41
  • @NomadMaker, I'm not talking about particular programming languages, java and c++ here is for illustration purposes only, and it's more about what representation is better to produce assembler code. Thus, my point is the it doesn't really matter, i.e. both approaches are equal. – Alexander Makarov Sep 01 '20 at 08:46
  • @AlexanderMakarov Sorry, but the only studies that I'd read were between Java and C/C++. You may be right, but I'd still go with my answer because of the overhead of running a VM and a JIT compiler. – NomadMaker Sep 01 '20 at 08:48

1 Answers1

1

Personally, I don't think so. Let's pick java that has a byte code and C++ for example. Both languages are considered as a high level languages, but java has a middle layer known as a byte code. Byte code is architecture agnostic that gives Java a power of "Write once, run anywhere". On other side, there is an overhead that's required for JVM to produce a bytecode out of java classes. Superiority of java bytecode over c++ code in terms of performance also questionable, because of both versions compiled back to assembler. Thus, in general, I would say that your statement is wrong. Here is a good reference on comparison between C++ code and JVM bytecode in terms of performance - C++11(native code) vs Java(bytecode)

  • There is no significant difference between assembly code and high level programming languages, because both approaches utilize optimized compilers to translate code into assembler code. – Alexander Makarov Sep 01 '20 at 08:13
  • my question is about machine code . Means which machine is better or more efficient one obtain from high level language or second obtain from assembly language . – Manjeet Singh Sep 01 '20 at 08:18
  • There is no difference in machine code as well, both approaches will be compiled back assembler, so it's more about how well compiler is written. – Alexander Makarov Sep 01 '20 at 08:36