Reputation: 489
Generally, we talk about comparison between speed of languages. What does this actually mean? I have heard many times that C is fast. How is C fast? Is Ruby not fast? How fast is javascript? Which is faster, Ruby or Python??
Upvotes: 1
Views: 832
Reputation: 825
Ruby Vs C
Ruby is a dynamically typed language whereas C is a static typed language. A language is statically typed if the type of a variable is known at compile time. This in practice means that you as the programmer must specify what type each variable is. Example: C, C++
A language is dynamically typed if the type of a variable is interpreted at run time. This means that you as a programmer can write a little quicker because you do not have to specify type every time. E.g Ruby.
Dynamically typed languages are generally slow because: 1. Compiling Ruby code is slow because the way Ruby handles reflection, features such as automatic type conversion from integer to big integer, and lack of static typing makes building an efficient compiler for Ruby extremely difficult 2. Dynamic languages have more information about the system at run time which can be used to optimize code. But in return it affects the performance as these additional informations need to be kept track of.
JavaScript Vs Ruby
JavaScript and Ruby have two different purpose to serve. JavaScript has to be downloaded, parsed, compiled, and run in real time while a (usually impatient) human being is waiting for it, it has to run WHILE a person is interacting with it, and it's doing this in an uncontrolled client-end environment that could be a computer or a phone. It HAS to be efficient in order to run under these conditions effectively. Python and Ruby are run in an environment controlled by the developer/deployer. For these languages library features are more preferred over speed optimization.
Any Corrections, suggestions, comments?
Upvotes: 1