[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2014-08-31
9
Medium Priority
?
344 Views
Last Modified: 2014-08-31
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

Rwniceing

Bash shell for loop with 2e6;
#!/bin/bash
for ((i=1;i<=200000000;i++))
do
a="$[1234+$5678+$i]"
b="$[1234*5678+$i]"
c="$[1234/2+$i]"
done

Open in new window

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

Open in new window

0
Comment
Question by:rwniceing
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:Manfred Bertl
ID: 40295361
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.
0
 
LVL 1

Author Comment

by:rwniceing
ID: 40295366
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
a
0
 
LVL 4

Expert Comment

by:Manfred Bertl
ID: 40295369
The Script in Linux runs within your shell (mostly bash, i guess). The Shell interprets the commands, hast to translate them and executes them.
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
LVL 1

Author Comment

by:rwniceing
ID: 40295373
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 .
0
 
LVL 4

Accepted Solution

by:
Manfred Bertl earned 2000 total points
ID: 40295374
Absolutely correct.
0
 
LVL 1

Author Comment

by:rwniceing
ID: 40295384
Optional question: Do you have any article to talk about this topic ?
0
 
LVL 4

Expert Comment

by:Manfred Bertl
ID: 40295411
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.
0
 
LVL 1

Author Closing Comment

by:rwniceing
ID: 40295420
the script's advantage and disadvantage mentioned in this link and some wording for
comparision from conventional program  langugage  at http://en.wikipedia.org/wiki/Shell_script

Thanks for your reply
0
 
LVL 4

Expert Comment

by:Manfred Bertl
ID: 40295426
Your are very welcome! Thanks for accepting the answer.

regards,
fred
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question