●リスト参照にかかる時間-2
リストの参照にかかる時間は、リストの要素の総数に比例する。前からそう感じていましたが、これまで実験したことはありませんでした。実験結果は思ったとおり比例してました。
set timeList to {}
set numList to {}
repeat 10000 times
set end of numList to 0
end repeat
--リストの総数が10000個の場合
set T to current date
repeat 5000 times --時間計測のため5000回繰り返す
item 1 of numList
end repeat
set end of timeList to (current date) - T
--リストの総数が5000個の場合
set numList to items 1 thru 5000 of numList
set T to current date
repeat 5000 times --時間計測のため5000回繰り返す
item 1 of numList
end repeat
set end of timeList to (current date) - T
--リストの総数が2500個の場合
set numList to items 1 thru 2500 of numList
set T to current date
repeat 5000 times --時間計測のため5000回繰り返す
item 1 of numList
end repeat
set end of timeList to (current date) - T
get timeList
結果{22,11,5}