●リスト参照にかかる時間-4
“参照にかかる時間-2”では参照にかかる時間は、リストの要素の数に比例していました。では、 a reference to を用いた場合はどうなるのか実験してみました。結果はリストの要素の数に関わらず、常に一定であることがわかりました。
set timeList to {}
set numList to {}
repeat 10000 times
set end of numList to 0
end repeat
--リストの総数が10000個の場合
set numListRef to a reference to numList
set T to current date
repeat 100000 times --時間計測のため100000回繰り返す
item 1 of numListRef
end repeat
set end of timeList to (current date) - T
--リストの総数が5000個の場合
set numList to items 1 thru 5000 of numList
set numListRef to a reference to numList
set T to current date
repeat 100000 times --時間計測のため100000回繰り返す
item 1 of numListRef
end repeat
set end of timeList to (current date) - T
--リストの総数が2500個の場合
set numList to items 1 thru 2500 of numList
set numListRef to a reference to numList
set T to current date
repeat 100000 times --時間計測のため100000回繰り返す
item 1 of numListRef
end repeat
set end of timeList to (current date) - T
get timeList
結果{4, 4, 4}