Interestingly enough, no one actually ever mentioned the truly fastest way to do loops in bash:
x=4000000
declare -i i=0
while ((i++ < x)); do # or ((++1<x))
:
done
For other than +1 iterations (slightly slower) use:
x=4000000
declare -i i=-1
while (((i += 1) < x)); do
:
done
, which is about 17% faster than the C-like for loop.
Also in general, if you need to do easy math outside a loop condition, always declare -i all used variables first. Then you can use simple i+=i-i+1i+=1 (works exactly like (()) with varname expansion, ie. no $ needed) instead of ((i+=1)). Never use let +=1 - it's always gonna be the slowest (just like declare i+=1).