refactor(examples): 为基准测试函数添加参数类型声明

- 为 Ack 函数添加 int 类型参数声明
- 为 ackermann 函数添加 int 类型参数声明
- 为 ary3 函数添加 int 类型参数声明
- 为 hash1 函数添加 int 类型参数声明
- 为 hash2 函数添加 int 类型参数声明
- 为 gen_random 函数添加 int 类型参数声明
- 为 heapsort_r 函数添加 int 类型参数声明
- 为 heapsort 函数添加 int 类型参数声明
pull/1/head
韩天峰 3 months ago
parent 56d9147972
commit bbddd40297
  1. 18
      examples/bench.php

@ -104,14 +104,14 @@ function mandel2() {
/****/ /****/
function Ack($m, $n){ function Ack(int $m, int $n){
if($m == 0) return $n+1; if($m == 0) return $n+1;
if($n == 0) return Ack($m-1, 1); if($n == 0) return Ack($m-1, 1);
return Ack($m - 1, Ack($m, ($n - 1))); return Ack($m - 1, Ack($m, ($n - 1)));
} }
function ackermann($n) { function ackermann(int $n) {
$r = Ack(3,$n); $r = Ack(3, $n);
print "Ack(3,$n): $r\n"; print "Ack(3,$n): $r\n";
} }
@ -163,7 +163,7 @@ function ary2($n) {
/****/ /****/
function ary3($n) { function ary3(int $n) {
for ($i=0; $i<$n; $i++) { for ($i=0; $i<$n; $i++) {
$X[$i] = $i + 1; $X[$i] = $i + 1;
$Y[$i] = 0; $Y[$i] = 0;
@ -190,7 +190,7 @@ function fibo(int $n) {
/****/ /****/
function hash1($n) { function hash1(int $n) {
for ($i = 1; $i <= $n; $i++) { for ($i = 1; $i <= $n; $i++) {
$X[dechex($i)] = $i; $X[dechex($i)] = $i;
} }
@ -203,7 +203,7 @@ function hash1($n) {
/****/ /****/
function hash2($n) { function hash2(int $n) {
for ($i = 0; $i < $n; $i++) { for ($i = 0; $i < $n; $i++) {
$hash1["foo_$i"] = $i; $hash1["foo_$i"] = $i;
$hash2["foo_$i"] = 0; $hash2["foo_$i"] = 0;
@ -218,12 +218,12 @@ function hash2($n) {
/****/ /****/
function gen_random ($n) { function gen_random (int $n) {
global $LAST; global $LAST;
return( ($n * ($LAST = ($LAST * IA + IC) % IM)) / IM ); return( ($n * ($LAST = ($LAST * IA + IC) % IM)) / IM );
} }
function heapsort_r($n, &$ra) { function heapsort_r(int $n, &$ra) {
$l = ($n >> 1) + 1; $l = ($n >> 1) + 1;
$ir = $n; $ir = $n;
@ -255,7 +255,7 @@ function heapsort_r($n, &$ra) {
} }
} }
function heapsort($N) { function heapsort(int $N) {
global $LAST; global $LAST;
define("IM", 139968); define("IM", 139968);

Loading…
Cancel
Save