Is there something wrong with my script or is Bash much slower than Python?
36
votes
9
answers
16149
views
I was testing the speed of Bash and Python by running a loop 1 billion times.
$ cat python.py
#!/bin/python
# python v3.5
i=0;
while i<=1000000000:
i=i+1;
Bash code:
$ cat bash2.sh
#!/bin/bash
# bash v4.3
i=0
while [[ $i -le 1000000000 ]]
do
let i++
done
Using 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?
Asked by Alex Jones
(6483 rep)
Aug 13, 2016, 08:43 AM
Last activity: Apr 18, 2025, 09:51 AM
Last activity: Apr 18, 2025, 09:51 AM