Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Coder's Corner Lounge (http://www.programmingforums.org/forum11.html)
-   -   How is it faster (http://www.programmingforums.org/showthread.php?t=16091)

JOORDEE Jul 4th, 2008 4:56 PM

How is it faster
 
Hi guys if you have seen some of my threads before you know im pretty ignorant of programming, but dont worry im starting school for c++ and other programming fundamentals in a month, but anyway ive got another question, when people make statements like c++ is better than c# because its faster,what does that mean, how can a language be faster than another one?

grumpy Jul 4th, 2008 5:47 PM

Re: How is it faster
 
It's not a speed of language issue as such. It's speed of execution of the programs after they are translated into a form they can be run. C++ allows the programmer to do things in which the program gets intimate with the system it runs on. The flip side of that is programming errors become more catastrophic (eg program crashes, system crashes) and it takes more effort for the programmer to eliminate mistakes.

C# does things make programming "safer" for the programmer (ie it prevents the programmer from doing dangerous things). Some of those techniques have no effect on program performance (eg eliminating "unsafe" coding constructs - although "unsafe" is usually a politically correct way of saying programmers are likely to use them incorrectly due to lack of understanding). However, some of the techniques (eg extra runtime checks, use of a virtual machine so a layer of software sits between the program and the system) do introduce runtime overhead.

That means a well-written C# program will run slower than a well-written C++ program equivalent. There are exceptions to that statement but, in practice, it's true more often than not. I use the qualifier "well-written" here deliberately. The water is muddied sometimes because several published "language comparisons" do not compare like with like. A well written C# program can out-perform a poorly written C++ program just as convincingly as a well written C++ program can outperform a poorly written C# program.

lectricpharaoh Jul 4th, 2008 10:05 PM

Re: How is it faster
 
If someone tells you that one language is better than another, without any qualifying factors (ie, better for a particular purpose), then they are probably full of shit (pardon my French). Certain languages are better suited to different tasks, and it's certainly true that most, if not all, programmers have one or more languages they're fond of.

It's also true that one language can generate faster code than another, for various reasons. In addition, even if using the same language, different compilers will emit different code. Two C compilers, for example, might generate binary code with markedly different performance characteristics.

Basically, there are three factors (besides the skill of the programmer) that determine how well the code performs. First is the language. Every language strives to be good at something, and if that something is performance for a particular type of task, it is likely to outperform languages not designed with that in mind. Some things that languages strive for besides performance might include ease of use (BASIC, Pascal, Python), web development (PHP), portability (Java and to some extent C# as well), and so on. The second factor is the target platform, which is the combination of operating system and hardware (and sometimes other aspects of the runtime environment, such as the desktop manager in use for a Linux system) that the program is designed to run on. If you're using a language that targets a virtual machine, such as Java or any of the .NET languages, then technically, the Java VM or .NET runtime is the target platform (though performance will differ depending on the underlying OS and hardware, as well). A VM-based target will often have a negative impact on performance, but in many cases, it is insignificant (even imperceptible). The last factor is the optimization used. Most compilers support different levels of optimization for different purposes, and optimizing for speed sometimes yields larger code, while optimizing for size can yield slower code. Hence, like many other things, there is a tradeoff involved, and what is 'best' depends on the situation.

The upshot of all this is that language A might be faster than language B for one set of circumstances, while for another set of circumstances, it might be the other way around.

JOORDEE Jul 5th, 2008 4:22 PM

Re: How is it faster
 
Thanks guys for helping to understand that


All times are GMT -5. The time now is 1:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC