You just want it to run a loop as fast as possible for a specific duration?
Code:
set start_value to do shell script "ruby -e 'print Time.now.to_f'"
repeat while true
-- Your code goes here
set end_value to do shell script "ruby -e 'print Time.now.to_f'"
if end_value - start_value ≥ 1 then
exit repeat
end if
end repeat
The above code will run through a loop for one second. Change the value in the if statement to adjust the amount of time. Note that you can also specify partial seconds, such as 2.5.
Can't help you with your other problem.