Mercurial > op > Looping
annotate Looping.py @ 11:b952a5d72c9f >>178
Luaのソースコードを追加。2ch.netからの転載。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Thu, 24 Feb 2011 22:23:25 +0900 |
parents | 57283e4fdd4b |
children |
rev | line source |
---|---|
0
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
2 import time |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
3 |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
4 class Looping: |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
5 "Looping Class" |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
6 n0 = 0 |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
7 def calc(self, n): |
3
57283e4fdd4b
Python版の式を修正。計測結果には変化なし。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
0
diff
changeset
|
8 n1 = self.n0 + (1 - 2*(n%2)); |
0
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
9 self.n0 = n; |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
10 return n1 |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
11 |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
12 if __name__ == "__main__": |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
13 s = Looping() |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
14 c = 0 |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
15 n = 1 |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
16 t1 = time.time() |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
17 while c<2147483647: |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
18 n = s.calc(n) |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
19 c = c + 1 |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
20 t2 = time.time() |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
21 print n, "Python\t", (t2 - t1) |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
22 |