what is the fastest language ?
-
xsx
- Kobold
- Posts: 31
- Joined: Tue Jan 20, 2009 10:38 am
- Location: egypt
what is the fastest language ?
Is the C++ the fastest programming language in performance ?
Who is faster ? C++ or C# ?
Do they have the same speed ?
Who is faster ? C++ or C# ?
Do they have the same speed ?
- xavier
- OGRE Retired Moderator

- Posts: 9481
- Joined: Fri Feb 18, 2005 2:03 am
- Location: Dublin, CA, US
- x 22
Re: what is the fastest language ?
It depends.
- jacmoe
- OGRE Retired Moderator

- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Re: what is the fastest language ?
Is your other topic not good enough?xsx wrote:Is the C++ the fastest programming language in performance ?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- Azgur
- Goblin
- Posts: 264
- Joined: Thu Aug 21, 2008 4:48 pm
Re: what is the fastest language ?
What is C#? Answer that question and you've answered your own original question.
- Klaim
- Old One
- Posts: 2565
- Joined: Sun Sep 11, 2005 1:04 am
- Location: Paris, France
- x 56
- Contact:
- Kojack
- OGRE Moderator

- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 538
Re: what is the fastest language ?
The fastest language is Assembly.
Everything has to become assembly at some point since that's all the cpu can execute.
However 99% of programmers are far worse at writing efficient assembly than an optimising compiler for a higher level language.
Everything has to become assembly at some point since that's all the cpu can execute.
However 99% of programmers are far worse at writing efficient assembly than an optimising compiler for a higher level language.
-
jjp
- Silver Sponsor

- Posts: 597
- Joined: Sun Jan 07, 2007 11:55 pm
- Location: Cologne, Germany
- Contact:
Re: what is the fastest language ?
For a software that equals a few hundred thousand lines of C++ assembly isn't going to produce the fastest program. Depending on the program it might even be practically impossible to code it in assembly at all for every programmer in existance. Obviously, the closer to the hardware a language is the more one can optimize code with it (with good knowledge of the hardware). But as programs get more complex more abstraction is needed to make things manageable for humans.
Enough is never enough.
- JohnJ
- OGRE Expert User

- Posts: 975
- Joined: Thu Aug 04, 2005 4:14 am
- Location: Santa Clara, California
- x 4
Re: what is the fastest language ?
jjp: That's a very good point actually. People always say assembly is the fastest language, but for a practical project, it would get impossible to manage without strict coding methodologies to keep things tidy. But then, you'll find that a C++ compiler can take code that's even more readable, and produce compiled code that's even more efficient, simply because it can perform automated optimizations throughout the machine code it compiles that you would drive yourself insane trying to maintain in a hand-coded assembly app.
The same thing actually applies to other languages, in that for certain tasks, C# may very well be "practically" faster than C++ for example. However, I do know that for games, C++ seems to be the fastest overall, probably because (in most benchmarks) it's many times faster than most other languages when it comes to mass data computations.
Also, keep in mind that saying "language A" is faster than "language B" is somewhat misleading; depending on the compilers/interpreters used, speeds will vary greatly. For example, MS Visual C# is overall a little faster than GCC / MingW C++ I believe, but MS Visual C++ beats all of them by a good margin.
BTW, I sometimes find it funny how people sometimes still say how C++ is slow compared to C because "higher level languages are inherently less efficient". If you look at modern benchmarks though, you'll probably be surprised to find that C++ is actually faster than C most cases. I think that because C++ is a higher level language, more information is supplied to the compiler (like const, etc.), and therefore better optimizations can be performed when compiling.
The same thing actually applies to other languages, in that for certain tasks, C# may very well be "practically" faster than C++ for example. However, I do know that for games, C++ seems to be the fastest overall, probably because (in most benchmarks) it's many times faster than most other languages when it comes to mass data computations.
Also, keep in mind that saying "language A" is faster than "language B" is somewhat misleading; depending on the compilers/interpreters used, speeds will vary greatly. For example, MS Visual C# is overall a little faster than GCC / MingW C++ I believe, but MS Visual C++ beats all of them by a good margin.
BTW, I sometimes find it funny how people sometimes still say how C++ is slow compared to C because "higher level languages are inherently less efficient". If you look at modern benchmarks though, you'll probably be surprised to find that C++ is actually faster than C most cases. I think that because C++ is a higher level language, more information is supplied to the compiler (like const, etc.), and therefore better optimizations can be performed when compiling.
- xavier
- OGRE Retired Moderator

- Posts: 9481
- Joined: Fri Feb 18, 2005 2:03 am
- Location: Dublin, CA, US
- x 22
Re: what is the fastest language ?
"const" has no impact on performance. The same code is generated for both const and non-const methods and parameters. The only difference is compile-time support against modifying const objects and pointers/references.
Now, if you meant to say "restrict" and "volatile" then you are on to something.
Now, if you meant to say "restrict" and "volatile" then you are on to something.
- JohnJ
- OGRE Expert User

- Posts: 975
- Joined: Thu Aug 04, 2005 4:14 am
- Location: Santa Clara, California
- x 4
Re: what is the fastest language ?
Really? Then why does this compile:"const" has no impact on performance. The same code is generated for both const and non-const methods and parameters. The only difference is compile-time support against modifying const objects and pointers/references.
Code: Select all
const int size = 10;
char array[size];Code: Select all
int size = 10;
char array[size];Anyway the point is C++ has a lot more language features, which when used properly, can result in faster executables than equivalent C code, according to most benchmarks
-
CABAListic
- OGRE Retired Team Member

- Posts: 2903
- Joined: Thu Jan 18, 2007 2:48 pm
- x 58
- Contact:
Re: what is the fastest language ?
Best example: C++'s sort vs. C's qsort. C++ wins the game because it can inline a comparison functor. C has to use a function pointer.
But that's really more cosmetics. For all practical purposes, you should take the language which you think makes your specific job the easiest to do *for you*. And in most cases it doesn't matter if your implementation is 10x slower (constant factor, not complexity) than someone else might have managed with a different language because it won't be noticable. There are, of course, exceptions
But that's really more cosmetics. For all practical purposes, you should take the language which you think makes your specific job the easiest to do *for you*. And in most cases it doesn't matter if your implementation is 10x slower (constant factor, not complexity) than someone else might have managed with a different language because it won't be noticable. There are, of course, exceptions
-
jjp
- Silver Sponsor

- Posts: 597
- Joined: Sun Jan 07, 2007 11:55 pm
- Location: Cologne, Germany
- Contact:
Re: what is the fastest language ?
In the end the programmer's time is more precious than computation time
At least most of the time.
Enough is never enough.
- syedhs
- Silver Sponsor

- Posts: 2703
- Joined: Mon Aug 29, 2005 3:24 pm
- Location: Kuala Lumpur, Malaysia
- x 51
Re: what is the fastest language ?
I think lets stick to the original question: what is the fastest language? I think it is machine code, err can that be considered as a language?
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
-
darke
- Halfling
- Posts: 94
- Joined: Mon Sep 08, 2008 3:30 am
Re: what is the fastest language ?
x86 machine code gets runtime (just-in-time?) "compiled"/interpreted into microcode, which the processor then executes. Provided the x86 opcode semantics hold, it can do lots of fancy optimizations and parallelization tricks. I'm guessing all the other processor types do something similar to maintain opcode compatibility across hardware versions. So yes, raw machine code would be considered a language if you were programming processors. 
Kinda like a very loosely typed, low level scripting language since everything's a number or a pointer?
Kinda like a very loosely typed, low level scripting language since everything's a number or a pointer?
-
jjp
- Silver Sponsor

- Posts: 597
- Joined: Sun Jan 07, 2007 11:55 pm
- Location: Cologne, Germany
- Contact:
Re: what is the fastest language ?
I think the original question makes no sense. It is too general. Or, the only possible answer is: it depends, there is no language that is fastest for every possible program.syedhs wrote:I think lets stick to the original question: what is the fastest language?
Enough is never enough.
- nikki
- Old One
- Posts: 2730
- Joined: Sat Sep 17, 2005 10:08 am
- Location: San Francisco
- x 13
- Contact:
- xavier
- OGRE Retired Moderator

- Posts: 9481
- Joined: Fri Feb 18, 2005 2:03 am
- Location: Dublin, CA, US
- x 22
Re: what is the fastest language ?
Your conundrum is irrelevant to the (lack of a) performance impact of the const keyword.JohnJ wrote:Really? Then why does this compile:"const" has no impact on performance. The same code is generated for both const and non-const methods and parameters. The only difference is compile-time support against modifying const objects and pointers/references.But not this:Code: Select all
const int size = 10; char array[size];Code: Select all
int size = 10; char array[size];![]()
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
Re: what is the fastest language ?
I thought compilers could make more assumptions about const variables, which allows them to optimize better?
-
darke
- Halfling
- Posts: 94
- Joined: Mon Sep 08, 2008 3:30 am
Re: what is the fastest language ?
NOP2k is far superior to FL 2000! All language features are expressed as NOPs, and it has a revolutionary NOP-optimising compiler that can speed up your program a thousand fold!nikki wrote:Well, you asked for it:
The fastest language is FL 2000 (FastLanguage 2000)! Its so fast, the program gives output before you enter your input. Cool!
It also doesn't have the reality warping, time paradox side effects of FL 2000 if someone distracts your coding mid-function. Plus it also doesn't attract Daleks.
- xavier
- OGRE Retired Moderator

- Posts: 9481
- Joined: Fri Feb 18, 2005 2:03 am
- Location: Dublin, CA, US
- x 22
Re: what is the fastest language ?
There are no assumptions about const that could have a performance impact. Like I said, though, "restrict" and "volatile" are two keywords that *do* have a performance impact.nullsquared wrote:I thought compilers could make more assumptions about const variables, which allows them to optimize better?
"const" in C++ is a language feature that allows code authors to enforce semantic usage of their APIs, is all.
- xavier
- OGRE Retired Moderator

- Posts: 9481
- Joined: Fri Feb 18, 2005 2:03 am
- Location: Dublin, CA, US
- x 22
Re: what is the fastest language ?
The answer, btw, is that the language requires array subscripts, when declaring an array, to be constant at compile time.JohnJ wrote: Really? Then why does this compile:But not this:Code: Select all
const int size = 10; char array[size];Code: Select all
int size = 10; char array[size];![]()
- JohnJ
- OGRE Expert User

- Posts: 975
- Joined: Thu Aug 04, 2005 4:14 am
- Location: Santa Clara, California
- x 4
Re: what is the fastest language ?
Yeah, I know why, I was just trying to make the point that "const" is a little more than a compile-time enforcement of variable const-ness
. You're probably right about it having no performance impact in most cases though, but it still seems logical that compilers at least should be able to do some extra optimization when encountering const variables. Either way, I still use it, for code correctness as well as theoretical optimization "potential"
.
Anyway, this is getting off topic, although the original question has pretty much been answered; C++ is generally faster than C#, and just about everything else, with a good compiler (like MS Visual C++).
Anyway, this is getting off topic, although the original question has pretty much been answered; C++ is generally faster than C#, and just about everything else, with a good compiler (like MS Visual C++).
- volca
- Gnome
- Posts: 393
- Joined: Thu Dec 08, 2005 9:57 pm
- x 1
- Contact:
Re: what is the fastest language ?
Maybe the const keyword has a performance impact - it still is better to pass const reference than a object copy if you need the method to not modify the original object.
My 2 cents: Whatever you do, there is no chance that byte-code oriented languages will outperform statically compiled once in both speed and memory requirements. (One exception is that the bytecode compiler can optimize for the more likely happening code paths, which is also kind-of possible on GCC with some keywords by hand). Although java seems to outperform C++ in some random cases (generally it doesn't), it eats a whole lot more memory while doing so. And we're not talking about the lazy garbage collector which makes the situation even worse. JIT is fun and all, but isn't it all just a waste of CPU cycles? (I understand it means practically zero portability costs)
Edit: Oh I see now the OP asked about C#. Without knowing it much, I'd say the same applies - slower startup with JIT (or worse performance with pre-JIT'ed binaries
).
My 2 cents: Whatever you do, there is no chance that byte-code oriented languages will outperform statically compiled once in both speed and memory requirements. (One exception is that the bytecode compiler can optimize for the more likely happening code paths, which is also kind-of possible on GCC with some keywords by hand). Although java seems to outperform C++ in some random cases (generally it doesn't), it eats a whole lot more memory while doing so. And we're not talking about the lazy garbage collector which makes the situation even worse. JIT is fun and all, but isn't it all just a waste of CPU cycles? (I understand it means practically zero portability costs)
Edit: Oh I see now the OP asked about C#. Without knowing it much, I'd say the same applies - slower startup with JIT (or worse performance with pre-JIT'ed binaries
- cdleonard
- Goblin
- Posts: 266
- Joined: Thu May 31, 2007 9:45 am
Re: what is the fastest language ?
Interesting article on "const optimization": http://www.gotw.ca/gotw/081.htm from Herb Sutter. Short version: xavier is right; const doesn't help.
- syedhs
- Silver Sponsor

- Posts: 2703
- Joined: Mon Aug 29, 2005 3:24 pm
- Location: Kuala Lumpur, Malaysia
- x 51
Re: what is the fastest language ?
I think Herb Sutter points that you shouldn't really be focusing on compiler optimization for const keyword whereas the biggest advantage is actually more to human. There are still possibility of optimizations on const like one case below:-
versus if
the last line can be simplified to int i = 70; for the latter code version.
Code: Select all
int a = 20;
int b = 10;
int c = 40;
...
...
// after some lines which may or may not change a,b,c values
int i = a+b+c;
Code: Select all
const int a = 20;
const int b = 10;
const int c = 40;
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me

