Re: [RFC] clamp

From: Date: Thu, 24 Jun 2021 00:15:38 +0000
Subject: Re: [RFC] clamp
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-115088@lists.php.net to get a copy of this message
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); } ``` Thanks, Tyson

« previous php.internals (#115088) next »