I was testing the speed of Bash and Python by running a loop 1 billion times.$ cat python.py#!/bin/python# python v3.5i=0;while i<=1000000000:    i=i+1;Bash code:$ cat bash2.sh#!/bin/bash# bash v4.3i=0while [[ $i -le 1000000000 ]]dolet i++doneUsing the time command I found out that the Python code takes just 48 seconds to finish while the Bash code took over 1 hour before I killed the script.Why is this so? I expected that Bash would be faster. Is there something wrong with my script or is Bash really much slower with this script?
Is there something wrong with my script or is Bash much slower than Python?
bash;python3
This is a known bug in bash; see the man page and search for BUGS:BUGS       It's too big and too slow.;)For an excellent primer on the conceptual differences between shell scripting and other programming languages, I highly recommend reading:Why is using a shell loop to process text considered bad practice?The most pertinent excerpts:Shells are a higher level language. One may say it's not even a language. They're before all command line interpreters. The job is done by those commands you run and the shell is only meant to orchestrate them....IOW, in shells, especially to process text, you invoke as few utilities as possible and have them cooperate to the task, not run thousands of tools in sequence waiting for each one to start, run, clean up before running the next one....As said earlier, running one command has a cost. A huge cost if that command is not builtin, but even if they are builtin, the cost is big.And shells have not been designed to run like that, they have no pretension to being performant programming languages. They are not, they're just command line interpreters. So, little optimisation has been done on this front.Don't use big loops in shell scripting.