OSDN Git Service

タグを打ち忘れていたついでに、html版ドキュメントを追加しました。
[ring-lang-081/ring.git] / docs / ja-jp / build / html / _sources / performancetips.txt
1 .. index:: 
2      single: 性能改善に関する情報; はじめに
3
4 ====================
5 性能改善に関する情報
6 ====================
7
8 Ring の性能改善方法を学びます。
9
10
11 .. index:: 
12      pair: 性能改善に関する情報; リストの作成
13
14 リストの作成
15 ============
16
17 用例:
18
19 .. code-block:: ring
20
21         ? "Create the list using the Range operator"
22         t1 = clock()
23         aList = 1:1000000
24         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
25
26         ? "Create the list using the For loop"
27         t1 = clock()
28         aList = []
29         for x = 1 to 1000000
30                 aList + x
31         next
32         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
33
34         ? "Create the list using the list() function and the For loop"
35         t1 = clock()
36         aList = list(1000000)
37         for x = 1 to 1000000
38                 aList[x] = x
39         next
40         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
41
42 実行結果:
43
44 .. code-block:: none
45
46         Create the list using the Range operator
47         Time : 0.48 seconds
48         Create the list using the For loop
49         Time : 0.79 seconds
50         Create the list using the list() function and the For loop
51         Time : 1.56 seconds
52
53 .. note:: リストの作成で for ループ、または list() 関数を使用するよりも、範囲演算子のほうが速いです。
54
55 .. note:: リストの追加で add() 関数を使用するよりも、連結演算子‘+’を使用したほうが関数呼び出しのオーバーヘッドが少ないため速いです。ただしソースコードの可読性は落ちる場合があります。
56
57 .. note:: 処理に時間が掛かり過ぎるため copy() 関数で数十万件を超える大量のテストデータを作成しないでください。
58
59 .. index:: 
60      pair: 性能改善に関する情報; 算術演算子
61
62 算術演算子
63 ==========
64
65 用例:
66
67 .. code-block:: ring
68
69         ? "Using * operator"
70         t1 = clock()
71         for x = 1 to 1000000
72                 out = x * 2
73         next
74         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
75
76         ? "Using *= operator"
77         t1 = clock()
78         for x = 1 to 1000000
79                 out = x
80                 out *= 2
81         next
82         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
83
84 実行結果:
85
86 .. code-block:: none
87
88         Using * operator
89         Time : 1.34 seconds
90         Using *= operator
91         Time : 0.47 seconds
92
93 .. note:: \* 演算子よりも \*= 演算子を使用したほうが速いです。
94
95
96 .. index:: 
97      pair: 性能改善に関する情報; len() と For ループの使用
98
99 len() と For ループの使用
100 =========================
101
102 用例:
103
104 .. code-block:: ring
105
106         aList = 1:1000000
107
108         ? "Using len() in the For loop"
109         t1 = clock()
110         for x = 1 to len(aList)
111         next
112         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
113
114         ? "Using len() before the For loop"
115         t1 = clock()
116         nMax = len(aList)
117         for x = 1 to nMax
118         next
119         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
120
121 実行結果:
122
123 .. code-block:: none
124
125         Using len() in the For loop
126         Time : 5.50 seconds
127         Using len() before the For loop
128         Time : 0.24 seconds
129
130 .. note:: Len() 関数は For ループ内ではなく For ループの手前で使用したほうが早いです。
131
132 .. index:: 
133      pair: 性能改善に関する情報; 関数とメソッドの呼び出し
134
135 関数とメソッドの呼び出し
136 ========================
137
138 用例:
139
140 .. code-block:: ring
141
142         ? "calling 100000 functions"
143         t1 = clock()
144         for x = 1 to 100000
145                 test()
146         next
147         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
148
149         o1 = new test
150
151         ? "calling 100000 methods using the dot operator"
152         t1 = clock()
153         for x = 1 to 100000
154                 o1.test()
155         next
156         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
157
158         ? "calling 100000 methods using braces "
159         t1 = clock()
160         for x = 1 to 100000
161                 o1 { test() }
162         next
163         ? "Time : " + ((clock()-t1)/clockspersecond()) + " seconds"
164
165
166         func test
167
168         class test
169                 func test
170
171
172 実行結果:
173
174 .. code-block:: none
175
176         calling 100000 functions
177         Time : 0.28 seconds
178         calling 100000 methods using the dot operator
179         Time : 0.36 seconds
180         calling 100000 methods using braces
181         Time : 1.19 seconds
182
183 .. note:: メソッドの呼び出しよりも、関数の呼び出しのほうが僅かに速いです。
184
185 .. note:: メソッドの呼び出しで弓括弧を使用するよりも、ドット演算子を使用したほうが速いです。
186