czw., 24 cze 2021 o 02:15 tyson andre <tysonandre...@hotmail.com>
napisał(a):

> Hello Kim Hallberg,
>
> > The RFC for the clamp function is now open and under discussion, you now
> have 2 weeks
> > to discuss, suggest improvements and open issues before voting is
> considered.
>
>
> From https://wiki.php.net/rfc/clamp -
>
> > Current userland implementations are handled in several ways, some of
> which use min and max to check the bound,
> > which is costly and slow when called often.
> > Because userland implementations are for the most part not
> cost-effective when called multiple times,
> > a language implementation is desired.
>
> I'd strongly prefer an actual benchmark for context and accuracy - is it
> actually faster or slower than the most efficient userland implementation
> and by how much?
> E.g. in an optimized NTS build with `CFLAGS=-O2`, opcache
> enabled(zend_extension=opcache, opcache.enable=1,opcache.enable_cli=1),
> and no debug configure flags, how many calls per second can be made on
> variable values of $num for both?
> (I'd assume over twice as fast as calling both min/max from another
> function, but possibly slower than efficient_clamp, but haven't run this)
>
> For userland implementations that did use min/max, they probably weren't
> performance sensitive for the application.
>
> ```php
> function efficient_clamp(int|float $num, int|float $min, int|float $max):
> int|float {
>     return $num < $min ? $min : ($num > $max ? $max : $num);
> }
> ```
>

Do we really need it?
IMO the performance of this is not gonna change anything much.
We're talking about nanoseconds here possibly.

I'm looking forward to Hello World RFC - that's also often implemented in
userland.

```php
function hello(?string $who = 'World', bool $return = false, bool $newline
= true): ?string {
    $str = "Hello {$who}!" . ($newline ? PHP_EOL : '');
    if ($return) return $str;
    echo $str;
}
```

I get an impression that we constantly add things into standard library
which are from a language perspective irrelevant
and that all could be developed in userland with no harm.

Cheers,
--
Michał Marcin Brzuchalski

Reply via email to