Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115103 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53672 invoked from network); 24 Jun 2021 09:25:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jun 2021 09:25:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 48E8D1804D9 for ; Thu, 24 Jun 2021 02:44:31 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 24 Jun 2021 02:44:30 -0700 (PDT) Received: by mail-il1-f178.google.com with SMTP id i17so5474715ilj.11 for ; Thu, 24 Jun 2021 02:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZPUGE0RMZdG5MEIx+2HEDbeYqC99Sm3RGbCLkNqyaVc=; b=pkf6ej3iRQQa0sWeL92l8J6xdFP2LX220gtvpQ54PMV2qcGXJGb4uFm+ZodhqizX/Y jgiq2L1Lpv+7EE5Q7ZfZuNXTcMYhPIGyr3C+u+jfIjZuqn2vzygRaHuDB8KPS3fL8n/d BgkF1oFVaDssvu6I98LgCHsByoQXHHerlxRrWBgnnWZZXovpwc7YbLllHvKiAbM+0gQl 7jC03EilunW+9gQuoEcLZuqtrLnLTr+cL6uvGqedrt9EbCPLYOq46AZNs5FSbIEYqsmz wU2+3avJBcGaJfgPYFTyIFGaOy5AAN9rkGGI4ISmzY28y7PkaD4fFghtIlf5FprE3Jye jK0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZPUGE0RMZdG5MEIx+2HEDbeYqC99Sm3RGbCLkNqyaVc=; b=p9vRsEMKa0wqFR8JEAY56MVjOdpcdrT+vt3VM+7iCMaHJIupLCSMY/xoon7hvysjGk JPLFBGLT0IhF2Jp6f+82ILyCOdBTyTYMmz/gtFzJ6tLLoVNhkGJlSGldHamjWM6U6ouM k3Aa3hJqadSH4nJ39FZeMQzIZxEc/SaI7DaZlKmxF61gH9wN2AvcnADINjuOIZxWGPSs WxMZadcHC2TVA2ZNSFU4eZO+/l9Wm3HLItuC7pnbFuFjhBRk9yz7mVb1TWo1n1gRcM0n NRRKmbYSSqzo0WmaPpUYPx0qHiqKt+7bf8zIlhYG0JBlKREfdCNpZZHpJ5wDpCXF22tA cjvg== X-Gm-Message-State: AOAM533Uy5LeusbSfx9+Qwe4wS054ywUdlIYY3xY/qfUsQLNVbUNQ4mf J15b/s0DbpFSBCSidIlQEW+Lymg8eVTDwmEpKU4= X-Google-Smtp-Source: ABdhPJzjeH9JYoEdlHoKEcihmWzQxuMJ6aCIJYWwvGrxc6fJFoZOpSbIHxUQnRw84kEARCjj0VojSWLkbWGh8J+GmPg= X-Received: by 2002:a92:7a07:: with SMTP id v7mr2743966ilc.224.1624527868402; Thu, 24 Jun 2021 02:44:28 -0700 (PDT) MIME-Version: 1.0 References: <0BBAA2F7-02D7-4AEE-B48A-97436A0D8E5D@gmail.com> In-Reply-To: Date: Thu, 24 Jun 2021 11:44:17 +0200 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000861fa505c57fde4a" Subject: Re: [PHP-DEV] [RFC] clamp From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000861fa505c57fde4a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable czw., 24 cze 2021 o 02:15 tyson andre napisa=C5=82(a): > Hello Kim Hallberg, > > > The RFC for the clamp function is now open and under discussion, you no= w > 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=3D-O2`, opcache > enabled(zend_extension=3Dopcache, opcache.enable=3D1,opcache.enable_cli= =3D1), > 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 =3D 'World', bool $return =3D false, bool $newl= ine =3D true): ?string { $str =3D "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=C5=82 Marcin Brzuchalski --000000000000861fa505c57fde4a--