Minecraft

Pages: 1234
Java on android is a whole different story. Dalvik, nor the newer ART are currently nowhere near in terms of performance to Oracle JVM. First versions of Dalvik even didn't have JIT at all, and the newer ones do only a very basic set of optimisations and can't even do full inlining that Oracle JVM does.
If you think of a language in terms of syntax and semantics and consider any code which compiles into machine code, then technically you'd be right. However, each language introduces it's own flavor of paradigms and this affects the optimization of the machine code.

C++ introduced some very useful concepts over C. I'm specifically thinking of dynamic memory allocation and polymorphism. These concepts make life much MUCH easier for programmers. Avoiding them can make code incredibly complicated, however they are very expensive operations. By using a language such as Ada or Pascal, you are forced to consider each step involved and can optimize for your particular purpose.

Therefore I postulate that language does affect performance.
that still has nothing to do with performance. if i were to write a c++ compiler completely by myself, then i can promise you that the python interpreter that ships with ubuntu would perform better running equivalent programs.
Maybe we have different definitions of performance. My definition is the amount of time required to execute a task.

If you apply best-practices associated with that language, your program's performance will be affected by your choice of language.
As a reference: Take ANY practice problem in codechef.com. You can see execution time, memory used, and language used for every submission. The top submissions are always done in ASM, PAS fpc. C solutions are always faster than C++ which is always faster than Java.

The following link contains 32000 individual submissions to a very simple problem. All code is compiled and executed on the same machine. It gives us a good sample for our statistical analysis and the pattern is always followed.
http://www.codechef.com/problems/TEST

Here's another one with 22000 submissions:
http://www.codechef.com/problems/HS08TEST

This one has 15000 submissions, but an interesting anomaly occurs where there is a C# solution which is faster than C or C++.
http://www.codechef.com/problems/INTEST
That problem is too simple. Most of the time was wasted on constant-time library initialization which is slowest for Java and fastest for ASM.

If you look statistics for hardest chalenges you will find that C++ either dominates over C or shares top results. Other languages are not representative here.

Also you do not have access to compiler/VM settings which can make a greate difference.
you arent understanding me. we have the same definition of performance. there is nothing in the standards of the languages that say that it has to perform well. it all depends on whats executing the source file.

edit: for example (this isnt neccesarily right. just an example):
lets say g++ > vc++ > python interpreter > c++ interpreter > nasm > jdk. now lets say i write a c++ compiler all by myself using all of the knowledge i know right now. because c++ is the language im compiling by your logic my compiler will perform better than the jdk, which is developed by many professional programmers.
Last edited on
As a simple example, suppose one was to grab the GCC backend source code and make it insert, for every generated instruction, ten instructions that didn't alter the program state. The generated code would still work correctly and that version of GCC could still be called a C++ compiler. Programs generated by it would be a few times larger and slower, but they would still be C++ programs, and one would still be unable to say anything about the performance of C++ programs.

Now, that said, I don't think " language has nothing to do with speed" is quite right, either. There are certain sets of semantics that can play better with the underlying architecture; at the same time, there are sets of semantics that allow for more optimization possibilities.
Helios went a third of the distance, but didn't quite reach it.

Consider a compiler so advanced, it could take an program you give it and alter the structure of the program, the algorithms, even the language used and the language features utilized so as to make the program as efficient as possible.

Current compilers have been slowly moving from being very dumb to being very smart, but they're nowhere near this smart. So, for current-day practical purposes, the language does matter to some extent. However, when I say the language doesn't matter, I'm talking theory - about the way things could be in decades to come.

I can be optimistic and hope that one day compilers will be really good at optimizing and inlining high-level code and even changing decisions you made for you, and you can call me crazy, but my point still stands. Unless I explicitly say that my stance is based on practicality, you can assume it's instead based on theory.
closed account (9jNRX9L8)
Actually no. You can't just write a program in another language and it'll make it instantly faster. You have to optimize it appropriately.

I'm sure that good Java code is better than terrible machine-language code. Of course the lower-level you get the more access you get to optimization. In turn it makes you as a programmer more responsible for the program.


That is incorrect. No programming language can run faster than machine language. Also from how you reacted to my comment I am just going to presume that you are a Java programmer that doesn't want any other language to be better than it.

Though, for people that don't know. Machine language is basically a bunch of 1's and 0's that a computer is coded in. A coding language like Java is just text you write into something. A computer program called a compiler then converts that text into machine language. So a Java compiler would convert a text file written in Java to a text file written machine language.
closed account (9jNRX9L8)
Sorry for the double post.

Though LB I agree with you on that. I hope that one day compilers arn't just dumb and smart for example today its just like this.

1
2
3
4
5
// Java Code:
if (1 == 2 / 2)
{
    string value = "correct";
}

then Java compiler converts it
1
2
3
4
5
// Machine Language (By the way this is fake (I don't know machine language))
0101000100010001111000
1000010000000100000010
0001110010101010100010
010100101010


though in another compiler if you wrote the same Java code it might convert it to more optimized machine code.
Last edited on
No programming language can run faster than machine language
I would like to see how you would run something which is not in machine language on your CPU.

So a Java compiler would convert a text file written in Java to a text file written machine language.
And all languages are translated into machine opcodes in the end. So that leaves us with that statement:
I'm sure that good Java code is better than terrible machine-language code.


Just an example
1
2
3
4
//C++ code
x <<= 1;
//ASM code
mul eax, 2;
They are doing same thing. Which will be faster? (presuming older CPU)

In your Java example it will optimise it to string value = "correct"; like every other adequate language compiler
Last edited on
Toggy11 wrote:
That is incorrect.
Oh really?
Toggy11 wrote:
No programming language can run faster than machine language.
What do you think machine language is? What do you think C compiles to? Do you realize assembly is a programming language?
Toggy11 wrote:
Also from how you reacted to my comment I am just going to presume that you are a Java programmer that doesn't want any other language to be better than it.
Did a Java programmer kill your parents?
Toggy11 wrote:
Though, for people that don't know. Machine language is basically a bunch of 1's and 0's that a computer is coded in.
You say that like there are actually 1s and 0s inside computers.
Toggy11 wrote:
A coding language like Java is just text you write into something.
What do you think an executable binary file is?
Toggy11 wrote:
A computer program called a compiler then converts that text into machine language.
I don't even...
Toggy11 wrote:
So a Java compiler would convert a text file written in Java to a text file written machine language.
The official Java compiler is incapable of producing machine code.
The official Java compiler is incapable of producing machine code.
I talked about JIT before... It actually does. But in runtime.
http://stackoverflow.com/questions/1503479/how-to-see-jit-compiled-code-in-jvm
That is incorrect. No programming language can run faster than machine language.
who told you that? at some point, machine language is involved in every execution

Also from how you reacted to my comment I am just going to presume that you are a Java programmer that doesn't want any other language to be better than it.
im going to assume that you have read a terrible tutorial on what is going on behind the scenes. fred uses c++ and ruby...

Though, for people that don't know. Machine language is basically a bunch of 1's and 0's that a computer is coded in.
no... machine code is not basically 1's and 0's. have you ever heard of a hex editor? also, if you think thats what a computer is coded in, take a look at this: http://www.jamesmolloy.co.uk/tutorial_html/ <-- writes the os in c.

A coding language like Java is just text you write into something.

true ill give you that.

A computer program called a compiler then converts that text into machine language.
no. it translates in to another (turing complete) language. for example someone could write a c++ -> python3 compiler.


So a Java compiler would convert a text file written in Java to a text file written machine language.

sure. i fail to see the point there


Though LB I agree with you on that. I hope that one day compilers arn't just dumb and smart for example today its just like this.

// Java Code:
if (1 == 2 / 2)
{
string value = "correct";
}


then Java compiler converts it
[code]
// Machine Language (By the way this is fake (I don't know machine language))
0101000100010001111000
1000010000000100000010
0001110010101010100010
010100101010
[code]

though in another compiler if you wrote the same Java code it might convert it to more optimized machine code.

a) compilers are very smart. are they invincible? no, they have problems, but they can do amazing thigns.
b) thats what compilers strive to do every day. there are people that just develop theories of optimizations


The official Java compiler is incapable of producing machine code.
I talked about JIT before... It actually does. But in runtime.

can i interject there? isnt there a front end and back end to each JIT compiler? the front end compiles to an intermediate form such as byte code, then the virtual machine translates the byte code on the fly. meaning that it wouldnt actually be compiling to machine code. is that correct or did i misunderstand things?
JIT is Just-in-time compiler. It is not unique for Java. It compiles perfomance critical parts to the native code directly on the fly. According to Pareto Principle, translating about 20% of the code to native, removes most of the perfomance hit incurred by interpreting language

http://en.wikipedia.org/wiki/Pareto_principle#In_software
i know what JIT is. i wasnt just referring to java. you could also do this in python. but thanks for the link and for clearing that up.
closed account (9jNRX9L8)
Well no programming language can run faster than machine language can it?
Thats like saying I can run faster than myself. It just generally doesn't make sense.

Also, you would be able to run something other than machine language on a computer. Machine language isn't just this magical thing which pops up on a screen. Your laptop/computer isn't just empty inside it acctually has some electricty and pistons moving around inside of it. It might be that typing 0001000 into machine language trigger some components to display a window on the screen. Machine language is just a set of commands. It does what you tell it and only what you tell it.
Your laptop/computer isn't just empty inside it acctually has some electricty and pistons moving around inside of it.


Are we talking about cars or computers here?
Toggy11 wrote:
Well no programming language can run faster than machine language can it?
What makes you think 1+1 in Java is any different from 1+1 in machine language?
Toggy11 wrote:
Thats like saying I can run faster than myself. It just generally doesn't make sense.
The reverse does not make sense, either - "I can run slower than myself".
Toggy11 wrote:
Also, you would be able to run something other than machine language on a computer.
Can you give an example you actually know of? All is takes to prove your point here is to give a valid example.
Well no programming language can run faster than machine language can it?

what do you think these things are compiling to? its all machine language. the difference is how well this machine code is generated.

Also, you would be able to run something other than machine language on a computer. Machine language isn't just this magical thing which pops up on a screen. Your laptop/computer isn't just empty inside it acctually has some electricty and pistons moving around inside of it. It might be that typing 0001000 into machine language trigger some components to display a window on the screen. Machine language is just a set of commands. It does what you tell it and only what you tell it.
im not saying its a magical thing. where did you get that? i also fail to see your point here. who said computers are empty yet still filled with pistons and electiricity? and your right, that might be the proper code to do that (its not) but what do you think c++ compiles down to make a window? it compiles down to 0001000 so that it can open a window too.
Everything that executes something is ultimately machine code. Java is often compiled into bytecode which in turn is executed by the the JVM which is probably implemented in C/++ (never really looked into it) which is compiled to assembly which is assembled into machine language. There is nothing that can execute logic without going to some sort of machine language that the CPU can understand.

EDIT: In a good majority of cases, the C you write will be faster than the Assembly you write. You have to be well experienced to understand how to write faster Assembly than an optimizing C compiler.
Last edited on
Pages: 1234