Is BASH very slow?
bash
Solution
Bash is slow in executing number-crunching. But that isn't what Bash was designed for.
Bash is very fast in whipping up a script for automating some repetitive action. It's fast to modify a faulty Bash script and run it again. It's fast to find out what exactly a Bash script is doing (as opposed to having to hunt down the source for the C executable you're looking at).
And the list goes on.
C and Bash are two very different breeds of languages and environments. If you complain about Bash being slow, you are using it for the wrong kind of problem.
"Do not complain that the screwdriver sucks at driving a nail into the wall."
Problem
I was solving this question on SPOJ - http://www.spoj.com/problems/ALICESIE/ What the question boils down to print (n+1)/2 This is my C code which passes in 0.03s ``` #include <stdio.h> int main() { int test, n; scanf("%d", &test); while(test--) { scanf("%d", &n); printf("%d\n", (n + 1) >> 1); } return 0; } ``` while this is my BASH code which gives Time Limit Exceeded ( i.e. > 1s ) ``` read test while (( test-- )) do read n echo "$(((n+1)/2))" done ``` Can anyone let me know why is this happening ? Is BASH very slow ? Thanks.