useless_php_optimize.md
· 674 B · Markdown
Ham
Всё проверяем в консоли (то есть без OPCache) с помощью кода:
```php
const LIM = 1_000_000_000;
$arr = [
'a' => 1,
'b' => 2
];
$start = microtime(true);
for ($i = 0; $i < LIM; $i++) {
<test1>
}
echo microtime(true) - $start . PHP_EOL . PHP_EOL;
$start = microtime(true);
for ($i = 0; $i < LIM; $i++) {
<test1>
}
echo microtime(true) - $start. PHP_EOL. PHP_EOL;
```
Итак:
- `array_key_exists('b', $arr) VS isset($arr['b'])` - 9 sec VS 8 sec
- `array_key_exists('c', $arr) VS isset($arr['c'])` - 8.4 sec VS 7.6 sec
- `$ox !== null vs is_null($ox)` - 4.6 sec VS 4.5 sec (в PHP7 было наоборот)
Всё проверяем в консоли (то есть без OPCache) с помощью кода:
const LIM = 1_000_000_000;
$arr = [
'a' => 1,
'b' => 2
];
$start = microtime(true);
for ($i = 0; $i < LIM; $i++) {
<test1>
}
echo microtime(true) - $start . PHP_EOL . PHP_EOL;
$start = microtime(true);
for ($i = 0; $i < LIM; $i++) {
<test1>
}
echo microtime(true) - $start. PHP_EOL. PHP_EOL;
Итак:
array_key_exists('b', $arr) VS isset($arr['b'])
- 9 sec VS 8 secarray_key_exists('c', $arr) VS isset($arr['c'])
- 8.4 sec VS 7.6 sec$ox !== null vs is_null($ox)
- 4.6 sec VS 4.5 sec (в PHP7 было наоборот)