Bash script - why is this script so slow?

Granted the three arrays contain 3x365400 pixel values. But this takes minutes. The same done in PHP takes three seconds including to get the image!

I am not very experienced in bash scripting, so it might have crucial error.

for index in ${!R_pixel_array[@]}; do
      blue_red=bc <<< ${B_pixel_array[index]}-${R_pixel_array[index]}
      green_red=bc <<< ${G_pixel_array[index]}-${R_pixel_array[index]}
      if (( $(echo "$blue_red < 10" |bc -l) )) && (( $(echo "$green_red < 10" |bc -l) )) && (( $(echo "${B_pixel_array[index]} > 100" |bc -l) ))
        then
          ((count=count+1))
      fi
done

Have you tried executing your COMMANDS asynchronously? Run the following to get syntax help

help coproc

Sounds good, but how would you use that in this case?

Btw. CPU is at 60% while comparing the numbers, which sound excessive.

This is not “bash” solution when using bc. I would use awk oneliner and it would be as fast as php.