running time between linux-script and C++ on linux

Dear Experts,

Linux script is more or less like interpreted scrip as javascript but working for different platform such as one is for browsers and other is for  linux system script, Right ? Is linux-script  based on Assembly , C or C++ language  ?
I tried one benchmark code speed testing for "fop loop"  with linux  "time" command ,
The execution time of the C++ program is  around 0.01 seconds(11 ms) but for the linux script,
the time is  34 seconds that is totally greater than C++.

Do you have idea to explain the different result ? Or the time difference is depended on
some linux system  differnt setting on using  memory for script and binary program  ?
 And attached just simple example code  for "for loop" program with iteration of 2e6

Please advise


Bash shell for loop with 2e6;
for ((i=1;i<=200000000;i++))

Open in new window

C++ for loop with 2e6
int main(){
int max = 2e6;
int a,b,c;
	int start = getMilliCount();
	for (int i = 0; i < max; i++) {
    a = 1234 + 5678 + i;
    b = 1234 * 5678 + i;
return 0;

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Manfred BertlManagerCommented:
Linux script is an interpreter language, while C++ Code ist compiled into machine code. Therefor C++ programs are that faster to run, because they run w/o that layer of the interpreter.
rwniceingAuthor Commented:
So  for ((i=1;i<=200000000;i++)) is just  command more than language in linux-script, Right ? How linux interprete the "for loop", (probably it won't translate to assembly langauge since it wont be compiled or linked) and I think linux system treat the "for loop" as command and directly call its related  binary code to achieve the result, Right ? If so, the speed might not be too slow on linux-script.

for example,
$ x="a"
$ echo x
Manfred BertlManagerCommented:
The Script in Linux runs within your shell (mostly bash, i guess). The Shell interprets the commands, hast to translate them and executes them.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

rwniceingAuthor Commented:
And it might be in shell linux script, it will create a lot of child process and memory to to complete task which is not as efficient as C++ binary code process. But for c++ binary code after complied and linked, it just create single thread or process and  the memory is used less than script .
Manfred BertlManagerCommented:
Absolutely correct.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwniceingAuthor Commented:
Optional question: Do you have any article to talk about this topic ?
Manfred BertlManagerCommented:
No, i'm very sorry, i have no article about that. There might be tons of articles, when you search for performance tuning when coding scripts or applications. So i'm afraid, i have to point you to the search engines available.
rwniceingAuthor Commented:
the script's advantage and disadvantage mentioned in this link and some wording for
comparision from conventional program  langugage  at

Thanks for your reply
Manfred BertlManagerCommented:
Your are very welcome! Thanks for accepting the answer.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.