set repetitions to 12 -- or other. The more repetitions, the more accurate the result.
set theTime to 0
repeat repetitions times
set timeStart to current date
-- HERE PUT YOUR TESTED SCRIPT'S ON RUN HANDLER
set theTime to theTime + ((current date) - timeStart)
end repeat
set theTime to (1000 * theTime / repetitions) as integer -- result as milliseconds
This tip is very useful for me to test code lines one by one, or some snippet of the script, or the whole script.
For example, getting all properties of selected in “Mail” messages results on my machine in 900 milliseconds (that is, 0.9 seconds) with 10 iterations:
set repetitions to 10 -- or other what you want.
set theTime to 0
repeat repetitions times
set timeStart to current date
tell application "Mail"
set aMessage to item 1 of (get selection)
tell aMessage
set aContent to content
set |source| to source
set |subject| to subject
set |sender| to sender
set |messageId| to message id
set messageSize to message size
set wasForwarded to was forwarded
set wasRedirected to was redirected
set wasRepliedTo to was replied to
set replyTo to reply to
set readStatus to read status
set junkMailStatus to junk mail status
set |id| to id
set flaggedStatus to flagged status
set flagIndex to flag index
set deletedStatus to deleted status
set backgroundColor to background color
set dateReceived to date received
set dateSent to date sent
set |mailBox| to its mailbox
end tell
end tell
set timeEnd to current date
set theTime to theTime + ((current date) - timeStart)
end repeat
set theTime to (1000 * theTime / repetitions) as integer -- result as milliseconds