Hi.
KniazidisR’s script doesn’t include the small amount of time it takes the repeat itself to execute, but does add two current date calls and some date math per repeat (although these only partially add to the timings). peavine’s does the opposite. Also, by subtracting the dates’ times instead of the dates themselves, it lays itself open to strange results if midnight occurs during the test!
In both cases, the time interval on which the final calculation is done is an exact number of seconds and is based on the number of date second boundaries crossed between the current date calls. So the “milliseconds” end result is likely to be far from accurate.
A more accurate result can be obtained by using NSDate in ASObjC. The interval result’s still in seconds, but with the fractional part included to quite a large number of decimal places:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set repetitions to 10
set startTime to current application's class "NSDate"'s |date|()
repeat repetitions times
delay 0.75 --or whatever
end repeat
-- startTime was so many seconds *ago*, so multiply the interval by *minus* 1000 for a positive number of milliseconds.
set thetime to ((startTime's timeIntervalSinceNow()) * -1000 / repetitions) as integer