Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100472 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67401 invoked from network); 8 Sep 2017 15:06:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Sep 2017 15:06:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 84.19.169.162 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 84.19.169.162 mail.experimentalworks.net Received: from [84.19.169.162] ([84.19.169.162:35560] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8B/B0-10715-9F1B2B95 for ; Fri, 08 Sep 2017 11:06:34 -0400 Received: from [10.23.162.124] (unknown [141.143.213.3]) by mail.experimentalworks.net (Postfix) with ESMTPSA id CC5C064C42; Fri, 8 Sep 2017 17:06:30 +0200 (CEST) Message-ID: <1504883189.2374.26.camel@schlueters.de> To: David Rodrigues , PHP Internals Date: Fri, 08 Sep 2017 17:06:29 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] array_filter vs for/foreach usage cost From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) Hi, On Do, 2017-09-07 at 15:13 -0300, David Rodrigues wrote: > I understand that array_filter() should costs more than for/foreach > because > it is a function call that call another function for each item, while > the > for/foreach is a language constructor that works on a way totally > different > and its optimized for this kind of job. The main cost in that is that array_filter has to create a copy of the array. An alternative is using an FilterIterator or generator or such which would make this a pipeline step. (with iterators there are multiple function calls, while the function descriptor is cached, making them relatively cheap) I'd focus on improving those. johannes