性能改善に関する情報¶
Ring の性能改善方法です。
リストの作成¶
用例:
? "Create the list using the Range operator"
t1 = clock()
aList = 1:1000000
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
? "Create the list using the For loop"
t1 = clock()
aList = []
for x = 1 to 1000000
aList + x
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
? "Create the list using the list() function and the For loop"
t1 = clock()
aList = list(1000000)
for x = 1 to 1000000
aList[x] = x
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
実行結果:
Create the list using the Range operator
Time : 0.48 seconds
Create the list using the For loop
Time : 0.79 seconds
Create the list using the list() function and the For loop
Time : 1.56 seconds
注釈
リストの作成で for ループ、または list() 関数を使用するよりも、範囲演算子のほうが速いです。
注釈
リストの追加で add() 関数を使用するよりも、連結演算子‘+’を使用したほうが関数呼び出しのオーバーヘッドが少ないため速いです。ただしソースコードの可読性は落ちる場合があります。
注釈
処理に時間が掛かり過ぎるため copy() 関数で数十万件を超える大量のテストデータを作成しないでください。
算術演算子¶
用例:
? "Using * operator"
t1 = clock()
for x = 1 to 1000000
out = x * 2
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
? "Using *= operator"
t1 = clock()
for x = 1 to 1000000
out = x
out *= 2
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
実行結果:
Using * operator
Time : 1.34 seconds
Using *= operator
Time : 0.47 seconds
注釈
* 演算子よりも *= 演算子を使用したほうが速いです。
len() と For ループの使用¶
用例:
aList = 1:1000000
? "Using len() in the For loop"
t1 = clock()
for x = 1 to len(aList)
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
? "Using len() before the For loop"
t1 = clock()
nMax = len(aList)
for x = 1 to nMax
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
実行結果:
Using len() in the For loop
Time : 5.50 seconds
Using len() before the For loop
Time : 0.24 seconds
注釈
Len() 関数は For ループ内ではなく For ループの手前で使用したほうが早いです。
関数とメソッドの呼び出し¶
用例:
? "calling 100000 functions"
t1 = clock()
for x = 1 to 100000
test()
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
o1 = new test
? "calling 100000 methods using the dot operator"
t1 = clock()
for x = 1 to 100000
o1.test()
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
? "calling 100000 methods using braces "
t1 = clock()
for x = 1 to 100000
o1 { test() }
next
? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
func test
class test
func test
実行結果:
calling 100000 functions
Time : 0.28 seconds
calling 100000 methods using the dot operator
Time : 0.36 seconds
calling 100000 methods using braces
Time : 1.19 seconds
注釈
メソッドの呼び出しよりも、関数の呼び出しのほうが僅かに速いです。
注釈
メソッドの呼び出しで弓括弧を使用するよりも、ドット演算子を使用したほうが速いです。