Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by rwniceing
at 2024-08-31 05:20:38
Point:500 Replies:9 POST_ID:829210USER_ID:12079
Topic:
Shell Scripting;Linux;C++ Programming Language
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;
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/bashfor ((i=1;i<=200000000;i++))doa="$[1234+$5678+$i]"b="$[1234*5678+$i]"c="$[1234/2+$i]"done 1:2:3:4:5:6:7:
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;"} 1:2:3:4:5:6:7:8:9:10:11:12:
Expert: mbertl replied at 2024-08-31 06:41:38
Your are very welcome! Thanks for accepting the answer.
regards,
fred
regards,
fred
Author: rwniceing replied at 2024-08-31 06:36:28
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
comparision from conventional program langugage at http://en.wikipedia.org/wiki/Shell_script
Thanks for your reply
Expert: mbertl replied at 2024-08-31 06:28:46
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.
Author: rwniceing replied at 2024-08-31 05:58:12
Optional question: Do you have any article to talk about this topic ?
Accepted Solution
Expert: mbertl replied at 2024-08-31 05:50:22
500 points EXCELLENT
Absolutely correct.
Author: rwniceing replied at 2024-08-31 05:49:16
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 .
Expert: mbertl replied at 2024-08-31 05:45:55
The Script in Linux runs within your shell (mostly bash, i guess). The Shell interprets the commands, hast to translate them and executes them.
Author: rwniceing replied at 2024-08-31 05:36:08
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
for example,
$ x="a"
$ echo x
a
Expert: mbertl replied at 2024-08-31 05:29:15
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.