Which is faster – C or shell scripting – and why?

5,535

Solution 1

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.

Solution 2

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?

Obligatory xkcd:

        Automation: In reality, ongoing development time outweighs the time saved by automating a task

Share:
5,535

Related videos on Youtube

Qqqq
Author by

Qqqq

Updated on September 18, 2022

Comments

  • Qqqq
    Qqqq almost 2 years

    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.