Poll

Which coding langauge is best for learning Torque?

C++
Java
Niether, does not matter

Author Topic: C++ and Torque Script  (Read 3733 times)

Sure it's not that slow, but it certainly not as fast as C++
It is just as fast as C++.

It is just as fast as C++.
I just looked it up, looks like this is true.

Huh, who would have guessed.

It is just as fast as C++.
Sorry but you're wrong. Java runs in a virtual machine; it interprets bytecode and converts it to object code (this is an oversimplification as it does many more optimizations but the abstraction works for my point). C++ compiles to object code and does not need any translation phase. Java's standard library might provide tools which speed up its programs to be faster than some C++ code but in raw benchmarks C++ will always win because there is no intermediary translation phase. To explain it from a different viewpoint, you can write faster algorithms in Python than in C++ if the Python implementation is more efficient. Whatever the case Java is indeed quite fast; there's no question about that.

Edit to answer the OP: C++ is quite the complex beast when you get down to the nitty gritty parts of the language though its pretty close to Java in terms of OO. Java also includes lots of standard library classes so as to make it very easy for the beginner programmer to create things quickly. I would recommend you learning either Java, C#, Python, or C++ if you want exposure to object oriented topics as well as gaining a useful tool not only in learning but to create programs to do your bidding.
« Last Edit: March 28, 2013, 08:45:01 PM by dotdot: reloaded »

Sorry but you're wrong. Java runs in a virtual machine; it interprets bytecode and converts it to object code (this is an oversimplification as it does many more optimizations but the abstraction works for my point). C++ compiles to object code and does not need any translation phase. Java's standard library might provide tools which speed up its programs to be faster than some C++ code but in raw benchmarks C++ will always win because there is no intermediary translation phase. To explain it from a different viewpoint, you can write faster algorithms in Python than in C++ if the Python implementation is more efficient. Whatever the case Java is indeed quite fast; there's no question about that.
What about this?
Quote from: http://stackoverflow.com/questions/145110/c-performance-vs-java-c
Generally, C# and Java can be just as fast or faster because the JIT compiler -- a compiler that compiles your IL the first time it's executed -- can make optimizations that a C++ compiled program cannot because it can query the machine. It can determine if the machine is Intel or AMD; Pentium 4, Core Solo, or Core Duo; or if supports SSE4, etc.

A C++ program has to be compiled beforehand usually with mixed optimizations so that it runs decently well on all machines, but is not optimized as much as it could be for a single configuration (i.e. processor, instruction set, other hardware).

Additionally certain language features allow the compiler in C# and Java to make assumptions about your code that allows it to optimize certain parts away that just aren't safe for the C/C++ compiler to do. When you have access to pointers there's a lot of optimizations that just aren't safe.

Also Java and C# can do heap allocations more efficiently than C++ because the layer of abstraction between the garbage collector and your code allows it to do all of its heap compression at once (a fairly expensive operation).

Now I can't speak for Java on this next point, but I know that C# for example will actually remove methods and method calls when it knows the body of the method is empty. And it will use this kind of logic throughout your code.

So as you can see, there are lots of reasons why certain C# or Java implementations will be faster.

Now this all said, specific optimizations can be made in C++ that will blow away anything that you could do with C#, especially in the graphics realm and anytime you're close to the hardware. Pointers do wonders here.

So depending on what you're writing I would go with one or the other. But if you're writing something that isn't hardware dependent (driver, video game, etc), I wouldn't worry about the performance of C# (again can't speak about Java). It'll do just fine.

I'm definitely not attacking Java, it's a very good language. To quickly pick out some points for extra clarification:

Quote
Generally, C# and Java can be just as fast or faster because the JIT compiler -- a compiler that compiles your IL the first time it's executed -- can make optimizations that a C++ compiled program cannot because it can query the machine. It can determine if the machine is Intel or AMD; Pentium 4, Core Solo, or Core Duo; or if supports SSE4, etc.
This is true though at the same time its a feature that you can write yourself in C++. So from that angle yes you can sometimes get more speed out Java out of the box.
Quote
Also Java and C# can do heap allocations more efficiently than C++ because the layer of abstraction between the garbage collector and your code allows it to do all of its heap compression at once (a fairly expensive operation).
Such an abstraction is highly subjective. Java and C# use system APIs to allocate their heap memory -- APIs that you can call yourself from C++. Sometimes you need to manage your own memory, if you're experienced you can usually get faster performance than Java.
Quote
Now I can't speak for Java on this next point, but I know that C# for example will actually remove methods and method calls when it knows the body of the method is empty. And it will use this kind of logic throughout your code.
I don't know why this was included in the argument. All modern compilers remove extraneous and uncalled code.
Quote
So as you can see, there are lots of reasons why certain C# or Java implementations will be faster.
He's right; generally you have to write in a very specific style of Java and C# to get maximum optimizations out of the VM/JIT compiler.
Quote
Now this all said, specific optimizations can be made in C++ that will blow away anything that you could do with C#, especially in the graphics realm and anytime you're close to the hardware. Pointers do wonders here.
Also applicable to Java.
Quote
So depending on what you're writing I would go with one or the other. But if you're writing something that isn't hardware dependent (driver, video game, etc), I wouldn't worry about the performance of C# (again can't speak about Java). It'll do just fine.
The performance of C# and Java are actually very close these days. Personally I like C# much better than Java and Mono is getting better and better but they're both quite good.

You have to remember that Java (as a whole) is written in a combination of C and C++. It's still bytecode and not going to ALWAYS be faster than C++ because of the garbage collector and the intermediary translation. It's not written in hand optimized assembler. As stated in the post its all about what you want to do. Sometimes you really don't want a garbage collector and sometimes its just really useful to have one. There's also the speed/memory tradeoff of these things.

You can look at some real benchmarks between Java and C++ here. If anyone wants to discuss/debate more about it (or talk anything programming) I would love to do it over PM.


TL;DR: Yeah you're probably right that for whatever OP is going to do he most likely is not going to notice any speed differences between the two languages for the kind of programming he's doing. Personally go with C#!