●リストの結合にかかる時間-1
前回のソートのハンドラの中の※印を付けた部分が、どの程度時間を割いているのかを調べるために、同じように結合を繰り返して時間を計測してみました。
結果は1000項目まで挿入結合した場合が0.7秒、5000項目が19秒という結果が出ました。
予測に反して時間がかかりすぎているので、しばらく考え込んでしまいました。
前回のソートのハンドラでは必ずしも結合せず、beginning of 〜、end of 〜 で済ませられるケースもあるので、そういうことかなとも思いました。しかし、項目数が増えればその出現確率は減るので不可思議な結果です。(原因に目星がついたので次回それを説明します。)
set theRec to {aList:{}}
set theRecRef to a reference to theRec
set aItem to 500
set timeList to {}
set T to current date
repeat 10 times --こちらは時間計測のため10回繰り返す
set aList of theRecRef to {500, 500}
repeat 1000 - 2 times
set aList of theRecRef to items 1 thru -2 of aList of theRecRef & {aItem} & items -1 thru -1 of aList of theRecRef
end repeat
end repeat
set end of timeList to (current date) - T
set T to current date
repeat 1 times
set aList of theRecRef to {500, 500}
repeat 5000 - 2 times
set aList of theRecRef to items 1 thru -2 of aList of theRecRef & {aItem} & items -1 thru -1 of aList of theRecRef
end repeat
end repeat
set end of timeList to (current date) - T
get timeList
結果 {7, 19}