set s to " test "
set timeStarted to current date
repeat while (current date) - timeStarted = 0
end repeat
set timeStarted to current date
set x to 0
repeat 10000 times
set x to x + 1
set answerLoops to my Trim(s)
if (current date) - timeStarted = 1 then exit repeat
end repeat
say x & " loops in a second, with " & ((count of s) - 4) & " extra characters" as text
on Trim(s)
-- Find first non-white character
set i to 1
repeat
try
if character i of s ≠ " " and character i of s ≠ " " then
exit repeat
end if
on error
exit repeat
end try
set i to i + 1
end repeat
set j to length of s
repeat
try
if (character j of s ≠ " " and character j of s ≠ " ") or j ≤ i then
exit repeat
end if
on error
exit repeat
end try
set j to j - 1
end repeat
return (text i through j of s)
end Trim