Thanks for the quick reply and the very detailed response, Paul.
In reality I'm using C++ in ROS on Linux with a while loop that is supposed to be running at 250Hz and the shell script was supposed to be a simple way to test the timing. But either way, this conversation thread has been enough...