Your bash code is doing string>int conversions.
I ran your original code on my macbook laptop (i5):
Middle
Plus: 1000000
Minus: 0
real 0m20.839s
user 0m19.425s
sys 0m1.391sThen I ran an updated version where I eliminated the conversions:
Middle
Plus: 1000000
Minus: 0
real 0m16.380s
user 0m15.342s
sys 0m1.025sThe above were with Bash 3.2.57, which comes standard on macOS 10.13.6
Finally, I ran the updated script using Bash 5.0.11:
Middle
Plus: 1000000
Minus: 0
real 0m10.185s
user 0m10.060s
sys 0m0.108sUpdated script:
declare -i accum=0
declare -i milvar=1000000
for i in {1..1000000}
do
((++accum))
((--milvar))
if (( $accum == $milvar ));
then
echo "Middle"
fi
done
echo "Plus: " $accum
echo "Minus: " $milvar
AIR.
PS: For giggles, I ran the updated script on my local Debian server (i7, Bash 5.0.3):
Middle
Plus: 1000000
Minus: 0
real 0m3.722s
user 0m3.665s
sys 0m0.057sDidn't run this on my Pi, which is a 3B model and slow as crap...LOL