- 新增AstNodeType::isScalar方法用于检查标量类型 - 在CompilerBase中添加对Expr_Yield和Expr_YieldFrom表达式的错误处理 - 修改变量表达式判断逻辑,排除标量类型的情况 - 添加digit_count示例程序用于数字位数计算性能测试pull/1/head
parent
d81c4cda62
commit
75a9309801
3 changed files with 46 additions and 1 deletions
@ -0,0 +1,37 @@ |
|||||||
|
<?php |
||||||
|
function digit_count(int $x) |
||||||
|
{ |
||||||
|
if ($x == 0) { |
||||||
|
return 1; |
||||||
|
} |
||||||
|
if ($x == PHP_INT_MAX) { |
||||||
|
return 20; |
||||||
|
} |
||||||
|
|
||||||
|
$count = 0; |
||||||
|
if ($x < 0) { |
||||||
|
++$count; |
||||||
|
$x = -$x; |
||||||
|
} |
||||||
|
|
||||||
|
while ($x >= 1) { |
||||||
|
++$count; |
||||||
|
$x /= 10; |
||||||
|
} |
||||||
|
return $count; |
||||||
|
} |
||||||
|
|
||||||
|
function main() |
||||||
|
{ |
||||||
|
$b = microtime( true); |
||||||
|
$n = 100_0000; |
||||||
|
$v = 123456789000; |
||||||
|
while($n --) { |
||||||
|
$r = digit_count($v); |
||||||
|
// $r = strlen(strval($v)); |
||||||
|
} |
||||||
|
|
||||||
|
$e = microtime( true); |
||||||
|
echo "sec: " . ($e - $b) . "\n"; |
||||||
|
var_dump($r); |
||||||
|
} |
||||||
Loading…
Reference in new issue