Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 4th, 2008, 3:56 PM   #1
JOORDEE
noob programmer hobyist
 
Join Date: Feb 2008
Location: Baltimore,MD,USA
Posts: 11
Rep Power: 0 JOORDEE is on a distinguished road
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?
__________________
I Want Dat Pie
JOORDEE is offline   Reply With Quote
Old Jul 4th, 2008, 4:47 PM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,209
Rep Power: 5 grumpy is on a distinguished road
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.
grumpy is offline   Reply With Quote
Old Jul 4th, 2008, 9:05 PM   #3
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,011
Rep Power: 5 lectricpharaoh will become famous soon enough
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.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Jul 5th, 2008, 3:22 PM   #4
JOORDEE
noob programmer hobyist
 
Join Date: Feb 2008
Location: Baltimore,MD,USA
Posts: 11
Rep Power: 0 JOORDEE is on a distinguished road
Re: How is it faster

Thanks guys for helping to understand that
__________________
I Want Dat Pie
JOORDEE is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
String array zhaozhou C++ 11 Jan 16th, 2008 3:53 PM
Which is faster? rsnd Assembly 31 Jun 7th, 2006 9:26 AM
can you solve it faster ergawy C++ 8 Apr 9th, 2006 10:54 AM
When is it faster to cache? Sane Python 5 Apr 2nd, 2006 3:11 PM
a simple 2d game, faster in pygame or pyopengl? cypherkronis Python 1 Jun 30th, 2005 7:57 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:00 AM.

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