Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128592 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id BA75B1A00BC for ; Fri, 29 Aug 2025 02:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756435271; bh=K6xj4P8kYaUIMR78DjsC0wBIw9+CdlAUuPqtnyvY6J4=; h=Date:Subject:To:References:From:In-Reply-To:From; b=EqLJ48eCgIvQM1xvguU0KI/UQiCAKsXK40M4ezobCD4TrMKt4WjED63Y14ICs6UyF 9yg9plcG8EBhjG9RcFyGywpVA1B39u4HzX6Ei9IWuKAyTdjixVGV9d0JsSycux5zVT ULwPsDsBgoVpfCpbFzzk3ukHA+UnpwiieXoPlbWfsFkipxFkrCDko7AFMZXSqsmdiM lShi/5MxlGw0n3yaUq7+FwRM1mMH0it6SW5BFwS3P3RSWpmcjiUf/f46U0Q5q2fnM4 flfOKUHdDyxRlTKYqcTIW7Si/661B02FvFHDtDhwDiFj8Cb4s/smmQ4/GEZUFt7T1z aabZd58oZAFrw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9130418005C for ; Fri, 29 Aug 2025 02:41:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from tasha.smtp.mailx.hosts.net.nz (tasha.smtp.mailx.hosts.net.nz [43.245.52.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 29 Aug 2025 02:41:08 +0000 (UTC) Received: from 122-57-11-211-adsl.sparkbb.co.nz ([122.57.11.211] helo=[192.168.1.67]) by tasha.smtp.mailx.hosts.net.nz with esmtpsa authed as varteg.nz (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim 4.96) (envelope-from ) id 1urp4U-007Rqn-1E for internals@lists.php.net; Fri, 29 Aug 2025 14:42:34 +1200 Message-ID: <4db81c8b-64ee-4bf6-9134-c233c8cb3f71@varteg.nz> Date: Fri, 29 Aug 2025 14:42:23 +1200 Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] Add clamp function To: internals@lists.php.net References: <1756361767126.3727989781.4204927711@yahoo.de> <3b1bd29cd42074b499d38e10cb97bf42@bastelstu.be> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Hosts-DKIM-Check: none From: weedpacket@varteg.nz (Morgan) On 2025-08-29 08:36, Tim Düsterhus wrote: > > > Since a big part of your argument in favor of the clamp() function is > “performance” (both in your reply here and in the introduction to the > RFC): Please add meaningful benchmarks to the RFC text that show how > much faster clamp() is actually going to be compared to alternative > solutions. > Another part of the argument is "complexity", as brought up in the original proposal. I notice that the offered implementation of this function relies entirely on zend_compare(). max/min special-case long and double arguments and compare them more directly, leaving cases like string/string, string/double, array/array, or boolean/null to be handled by zend_compare(). It is a lot more complex, turning less than a dozen lines (looping over and passing args to zend_compare()) into more than fifty, presumably for performance reasons. The extra complication may not be worth it if there are only two or three values being compared (long and double are the first types zend_compare tries).