annotate Looping.php @ 5:861b93741d60

id:sumim氏のSmalltalk版とRuby版のコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Thu, 17 Feb 2011 11:32:17 +0900
parents b99b69fd33aa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
1 #!/usr/bin/env php
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
2 <?php
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
3 class Looping
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
4 {
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
5 private $n0 = 0;
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
6 public function calc($n) {
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
7 $n1 = $this->n0 + (1 - 2*($n%2));
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
8 $this->n0 = $n;
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
9 return $n1;
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
10 }
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
11 }
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
12
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
13 $s = new Looping();
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
14 $c = 0;
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
15 $n = 1;
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
16 $t1 = microtime(true);
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
17 while ($c<2147483647) {
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
18 $n = $s->calc($n);
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
19 $c++;
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
20 }
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
21 $t2 = microtime(true);
b99b69fd33aa PHPのベンチマークを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
22 echo $n, " PHP\t", ($t2-$t1), "\n";