●リスト参照にかかる時間-1
スクリプト自体はリストの最初の要素の値よりも小さいものはいくつあるか、というものですが、リスト中にある何度も使う値にあらかじめ変数名を付けておくか、毎回参照するか、の違いでどの位時間に違いが表れるかという実験です。
結論をいうと、私のパソコン(G4 1.25*2)では、あらかじめ変数名を付けた場合が9秒、毎回参照した場合が17秒、ほぼ倍の結果が出ました。
もう一方の比較する側も参照であることを考えれば、ほとんどの時間を参照に使っていることが分かります。
set N to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
set numList to {}
repeat 1000 times
set end of numList to (some item of N) * 100 + (some item of N) * 10 + (some item of N)
end repeat
set timeList to {}
--何度も参照する値にはあらかじめ変数名を付けた場合
set T to current date
repeat 20 times --実験データを得るために20回繰り返す
set A to 0
set theItem to item 1 of numList --あらかじめ変数名を付けておく
set i to 2
repeat (count numList) - 1 times
if theItem > item i of numList then
set A to A + 1
end if
set i to i + 1
end repeat
end repeat
set end of timeList to (current date) - T
--比較する際に毎回参照した場合
set T to current date
repeat 20 times --実験データを得るために20回繰り返す
set A to 0
set i to 2
repeat (count numList) - 1 times
if item 1 of numList > item i of numList then
set A to A + 1
end if
set i to i + 1
end repeat
end repeat
set end of timeList to (current date) - T
get timeList
結果{9, 17}