C++ Faster?

by 10 replies
12
Guys I just had a lecture in OOP and the lecturer said something like:

"The fastest Programming Language is C++"

I don't know what that meant and why?

Can anyone help me out? Thanks
#programming #faster
  • What he said is absolute bollocks
    The lecturer is a lecturer because he doesn't have enough knowledge to work as a programmer in the real world.
    There is no such thing as a fastest programming language. Its horses for courses, thats why there are so many of them.
    Fastest at what exactly?
    Machine code will be faster than C++ as it works at the machine level, but it will take longer to write a machine code program to do certain things than it would in C++
    A statement like C++ is the fastest programming language is the same as making a statement that a Ferrari is the fastest car.
    Which then becomes rubbish when I tell you I need the fastest car to take 8 people from Berlin to Paris.
  • Where's the applause button?

    I agree with what the poster said above. I probably wouldn't go as far as to say he couldn't make it in the real world. Maybe he wants to give back his knowledge with people. Just because he's teaching doesn't mean that he couldn't hack it.

    As far as why C++ is the fastest language ... (which it isn't) it's because 1 it's a compiled language. Compiled languages/programs have an advantage over interpreted languages (PHP is a great example). That's because compiled languages are broken down to machine code which the computer doesn't have to think about what it's doing. Think of it this way - Person A (C++) walks up to you and starts talking to you in your native language (compiled code) and you can do exactly what he wants because you can understand each other. Person B (PHP) walks up to you and makes the same request but it's in their language (interpreted) but you understand because you're a smart cookie - but it takes a bit longer because they are not talking to you in your native language.

    Make sense?

    C++ is faster - but what is it compared against? C++ is not faster than C and certainly not faster than Assembly language.
    • [1] reply
    • Definitely, it makes sense. Great explanation and example there mate!

      The lecturer compared C++ to other high level languages such as JAVA etc...

      Thank you very much.
      • [2] replies
  • Banned
    [DELETED]
  • I think that the professor might be saying it in the way that it is fast object oriented programming language. It is closer to the hardware I agree that but I think C is the most powerful one besides assembly.
  • But don't get it wrong, C++ is extremely fast: more than 200 times faster than PHP in many cases.

    C, Java, and C++ all test in about the same range, with Java being faster at some things like object binding, and C and C++ being barely, but consistently faster than Java in the majority of benchmarks.

    Another fast language (that uses the JVM) is Scala.
  • If you want to compare execution speed of any algorithm, then Java is comparable, sometimes even faster than C++, but those are "lab benchmarks". Language itself is the last thing to consider with regard to speed.

    In programming and in life in general, there's this 80-20, or even 90-10 rule, which says, that 10% of the code takes 90% of execution speed.

    Let's say you have a website. You optimize your HTML generating library by 400%, which in result might be like 0,2ms difference, but what you don't realize is that connecting to the database takes 40ms.

    This is called Premature Optimization, it's basically trying to optimize before knowing and HAVING PROOF that you actually need it. By having proof I mean running profiler to figure out which parts of code take how long to execute.

    I can't stress out how important this is, it's the number one mistake all programmers make. Never ever ever ever ever ever optimize unless you know you you actually need to do it in that specific part of code, or you will waste incredible amounts of time on getting no result.

    You can go as far as writing obviously "slow" code to realize, that in the 50 methods you wrote this day, onle one was as slow as it seemed and needed to optimize.

    This way you might find out that you have one method that is called 40 000 times, while the others are called <100 times. That is the only time when you want to get into microoptimalization.

    In result, you might come to thinking that C++ is sometimes faster, so you write that part of code in native code and call it via JNI or something similar. That should work out right? But what if loading the native code to memory is slower than executing the same thing in Java? ...

    Can you see now, that speed is not about the language? C++ might be faster in some way, but Java is much faster to develop in, meaning you have more time to optimize the code.

    In lab settings, C++ is probably faster, but if you're writing big application, Java might give you 10% slower execution, but you also get 200% faster development so you can find those 10% that are slowing you down and optimize it.

    I have experience with programming in Java, Ruby, PHP and C++ and I can tell you, that even though PHP and Ruby is sometimes more than 4 times slower than C++, it doesn't matter at all. Unless you're working for NASA or doing some heavy math/physics simulations, in which case you wouldn't ask the question
    • [ 1 ] Thanks
  • It maybe the fastest low level/high level hybrid language

Next Topics on Trending Feed