Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101959 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61198 invoked from network); 8 Mar 2018 18:23:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2018 18:23:06 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-it0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:51414] helo=mail-it0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/E2-27785-38F71AA5 for ; Thu, 08 Mar 2018 13:23:01 -0500 Received: by mail-it0-f42.google.com with SMTP id u66so8744939ith.1 for ; Thu, 08 Mar 2018 10:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=s588xAoAoTcnNd4/ibLdazC4yB7b4N+ZFPcvYFOg3rE=; b=a85NvqcOAhMtxobp0rLAoGM71aABQhNnyt20MS4FzlERJO85f6Yg7ZknRfOmzEo8AS OWVniNZ0jI99AoOhPC9n2xQ6ztvgehLLHw3ma6DpRmkaIjTU7zirXS58gjvLiwqQpDdG hqcQzvT9N7lTYzcBnlgiyTIJty5MbDEeQOb4Emm4dXeJLo9PD0cwUX6Ap/o6oUa1cu+a figpqPw1TXzMrgWMRjdIdFr6K/yCRzMHMDkAlKwzHwolRiHaEP60IqzBJtV2iXin6ccA WaQlwjpyiW5T96xgu7htyX9nzU0RwSZYwX0Lp4M+dhf6+A6RLcySTR7ihEP9Fru2oQf4 5gNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=s588xAoAoTcnNd4/ibLdazC4yB7b4N+ZFPcvYFOg3rE=; b=XXUNqYgeQQSV88zVbbz+jX8QbrloBhufQWpn4e5wOwxLAOYy76rV4yIqsLpbi7Lwh3 IuMkezc9+chPIarQ8HFM8g/7Yz2PDsVfLfmylaLVqe7ZMLQb+Vj+609yYQKFJ104zHK6 oL3Btm4bLHLhHGppiB52XHDjr24j7nopSwS//FUxzttkynBox75HO99EFfopsdDECqdM NY1R4jb0NxctAxjfiBZN8DlAU3jwbzV3krzCt8aGlRqDtBirpkMn1Ha0RjFykYDLkrHV F8fxLbROMJ3Y1HN1pdiomLJMsBKcUX7kvJvYSTIwGN5va65Ss5VLdfEdh2snmMNQBES/ wb8A== X-Gm-Message-State: AElRT7GKovnnh0dr72QMwIaWecQPbKrLB14oIpOmyN0l9dwG/UQvXIpp D0a2lVjmqo1KGySQmoovg1EKHuqhe8tzEuHp17c= X-Google-Smtp-Source: AG47ELtGQnVmTMECBwoNn7zAzueWUGtxTwSuAppy2eGqaVZLrEemKfvi6ZAs3e+BloW3j0oCYkbO4LXllv+q2mRrhzI= X-Received: by 10.36.196.130 with SMTP id v124mr15389071itf.39.1520533376847; Thu, 08 Mar 2018 10:22:56 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.118.74 with HTTP; Thu, 8 Mar 2018 10:22:36 -0800 (PST) In-Reply-To: References: Date: Thu, 8 Mar 2018 15:22:36 -0300 Message-ID: To: Nikita Popov Cc: PHP Internals Content-Type: multipart/alternative; boundary="94eb2c05b8cacbd4090566eac310" Subject: Re: [PHP-DEV] Direct method call slower than method_exists() From: david.proweb@gmail.com (David Rodrigues) --94eb2c05b8cacbd4090566eac310 Content-Type: text/plain; charset="UTF-8" Case #1: https://pastebin.com/cT0gWuNH Case #2: https://pastebin.com/724v9rBZ Case #3: https://pastebin.com/9zXpztCc Case #4: https://pastebin.com/q87p9S4r 2018-03-08 14:52 GMT-03:00 Nikita Popov : > On Thu, Mar 8, 2018 at 6:41 PM, David Rodrigues > wrote: > >> I have take note that a lot of projects (like Laravel) prefer uses >> method_exists() than implements an empty function (that should be useful >> to >> IDE when it is not annotated as an @method on class). >> >> For some reason, method_exists() will works faster than direct call when >> method doesn't exists vs. a direct method call when method is empty. >> >> My benchmarks: >> >> Case #1: >> * Direct call, empty method: >> * Cycles by min. : 26.459.804 >> >> Case #2: >> * Direct call, simple content (eg. is_bool(true)): >> * Cycles by min. : 24.771.454 >> - 6.38% slower than Case #1 >> >> Case #3: >> * method_exists(), no method: >> * Cycles by min. : 45.014.690 >> - 70.12% faster than Case #1 >> >> Case #4: >> * method_exists(), method exists with simple content: >> * Cycles by min. : 18.068.555 >> - 27.06% slower than Case #2 >> >> You will note that method_exists() will be more useful when method doesn't >> exists (+70% faster), but worse in cases where it does (27% slower). Which >> make that a hard decision, because you need "guess" the method declaration >> usage when implements something like that. If case the method existence is >> very low, then you will prefer method_exists(), which is bad for code >> design. >> >> My suggestion here (that I don't know if could be applied as is): identify >> empty methods and avoiding the execution (once that it will not do >> anything >> anyway). So we could just implement empty methods without any problem. >> >> Maybe it could be done at this point and related: >> https://github.com/php/php-src/blob/master/Zend/zend_languag >> e_parser.y#L725 >> >> -- >> David Rodrigues > > > Could you please provide the used benchmarking code? > > Nikita > -- David Rodrigues --94eb2c05b8cacbd4090566eac310--