macos – How can I make this script faster?

Below is a script designed to press the up arrow each time a pixel's # 535353 is met at 555.888. This is meant to create a bot for the Chrome Dino game. However, for some reason, the script does not always successfully press the up arrow when a cactus passes through. 555.888. I think that's because the script does not run the shell command to test the pixel quite often.

Is there a more efficient way to test the color of a pixel on the screen so that I can test it several times per second?

repeat
put px at ""
set px on (shell script "screencapture -R555,888,1,1 -t bmp $ TMPDIR / test.bmp &&
xxd -p -l 3 -s 54 $ TMPDIR / test.bmp |
sed (s)  \ (.. \) \ (.. \) \ (.. \) / \ 3 \ 2 \ 1 / & # 39; ")
if px contains "535353" then
tell the application "system events"
key code 126
end say
end if
end of repeating