Jenn: How is the speed of programming languages measured?
I know that people say that one programming language is faster than another and that C is a really fast programming language but is there an actual unit in which the speed of programming languages are measured? Like the number of lines executed per second on a computer that has a speed of one GHz or something?
Answers and Views:
Answer by Bill C
Typically you’ll take a particular test… Like sorting a million integers or doing some sort of a physics calculation or difficult mathematical operation. Pick something that’ll take a decent amount of time to run – say a minute or two.
Then, you code up the test in a bunch of different languages (typically in a straight forward manner, not doing any fancy tricks) and see how long they each take.
Obviously different algorithms and stuff will have different results, as each different language has strong and weak sections.
The reason a language like C or C++ are considered very fast is because they are compiled, so when you are running the program you are running in the native language of the computer (machine code). This is different than a language like Javascript which is an interpreted language (it has to do string operations and stuff when running the language). This makes a LOT of difference. Also, C is much lower level language than say Visual Basic, so when you tell the program to do something in C – it does only that, and it does it directly. In Visual Basic there are extra checks that are done to make sure that what you are doing doesn’t explode.
Generally, languages are organized by their speed, flexibility, and safety. A language like Javascript is very safe and flexible, but not very fast. C/C++ is very fast, but more strict and not safe at all.
Answer by Little PrincessThere isn’t really anything intrinsic about C that makes it faster than another language. The most important thing that influences how fast a program in one language is than another is how the program designed the code. Some languages allow for better optimization than others. C and C++ can be optimized to run real well. The other thing is that some processes lend themselves to one language more than another. If you’re doing a whole series of FFTs, then cuda is probably going to be the fastest. If you’re doing a bunch of user I/O, then something like VBasic or Cobol might be better suited.
So, determine what your particular needs are, then from that you can better decide which language is best suited for your needs.
Leave a Reply