●文字列から一文字を取得した場合の時間計測
3000文字からなる文字列を作成し、それぞれ1番目、100番目、1000番目、2000番目目、3000番目、最後、最後から3000番目の文字を取得するためにかかる時間を計測してみました。
1番目の文字を取得する時間に比較して、1000番目で2倍、2000番目で3倍、3000番目で4倍と比例しているのが分かります。(AppleScript は1バイト長の文字も2バイト長の文字も、character 1個と数えるので、前から一文字ずつ調べているということでしょうか)
最後から数える方法をとると、最後の文字(つまり3000番目)と最後から3000番目の文字(つまり1番目の文字)を取得するのに15秒程余計に時間がかかっています。(これは文字列の文字数をカウントし、それが前から何番目かという変換をしているのではないかと思います)
--3000文字からなる文字列を作成
set aText to ""
repeat 3000 times
set aText to aText & "あ"
end repeat
set timeList to {}
--1番目の文字を取得するための時間を計測
set T to current date
repeat 1000000 times
character 1 of aText
end repeat
set end of timeList to (current date) - T
--100番目の文字を取得するための時間を計測
set T to current date
repeat 1000000 times
character 100 of aText
end repeat
set end of timeList to (current date) - T
--1000番目の文字を取得するための時間を計測
set T to current date
repeat 1000000 times
character 1000 of aText
end repeat
set end of timeList to (current date) - T
--2000番目の文字を取得するための時間を計測
set T to current date
repeat 1000000 times
character 2000 of aText
end repeat
set end of timeList to (current date) - T
--3000番目の文字を取得するための時間を計測
set T to current date
repeat 1000000 times
character 3000 of aText
end repeat
set end of timeList to (current date) - T
--最後から1番目の文字(3000番目と同じ)を取得するための時間を計測
set T to current date
repeat 1000000 times
character -1 of aText
end repeat
set end of timeList to (current date) - T
--最後から3000番目の文字(1番目と同じ)を取得するための時間を計測
set T to current date
repeat 1000000 times
character -3000 of aText
end repeat
set end of timeList to (current date) - T
get timeList
結果{9, 11, 20, 29, 39, 54, 25}