2

I was looking for a detailed info (if possible some statistics) about which is faster to run, C or a shell script. And also I would like to know the reasons for the answer.

P.S. This is not a question of which is better, I know when to use C and when to use shell scripting, but I just wanted to know more about their speed and performance comparisons.

4

It depends.  Browse this site (look for posts with negative scores) and you'll see some examples of horrible shell scripts, doing things like reading a file one line at a time and then echoing each line into a program that could have just handled the entire file.  Naturally a script like that will run slowly.

But, if there is an existing program (or a small group of programs) that do exactly what you want, without too much baggage, then you can probably write a script very quickly that will run faster than any C program you can write, without a serious development effort.  A lot of time and energy has been invested in making some of the GNU/Linux programs very efficient.  For example, under some conditions, GNU grep doesn't need to look at every character of its input.  Will the program you write be that clever?

3

Shell is interpreted, and by itself that means it cannot be as fast as an specially-coded application — provided that what executes is written by equally competent programmers.

More than that, the answer depends on how you count the time: you should count development time as well as the execution time of a script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.