Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79279 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50385 invoked from network); 28 Nov 2014 14:46:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Nov 2014 14:46:54 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.44 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.218.44 mail-oi0-f44.google.com Received: from [209.85.218.44] ([209.85.218.44:48304] helo=mail-oi0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/6E-59154-CDA88745 for ; Fri, 28 Nov 2014 09:46:53 -0500 Received: by mail-oi0-f44.google.com with SMTP id e131so4753478oig.17 for ; Fri, 28 Nov 2014 06:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=o6mJW90zfU2OxFf70p1KN7Wv0mn5+W8ehi1/x5I1seU=; b=B0HhCvGOd96lW2IQoQmgQQf28225tqPFjIfoET4nFa3emFvv9naMv8i4Y+9DoKfhRg LfyZWyDIBm0Jtz3J6EsPUNM5xyex+xCF5TKAS6z3BpRzmyIU8139yLn7gjySnllQmQq3 zy7yhNnSMIXLgCcJQ8eRe+TpgJw7pDajFNz10PVj1cmSlP/9ZcmbJFeJLIjhxwYhVrqb UukPxx17GWgEwzi3pWXXsJiQHBoL3UT2fbRkAqhMk8nLfeXkwc7muxTqHQP0MIuniScj N/lRAAhjVsdF9DBFDMOflr41TT0nqLglGlzUfKAVVVXfDM5WOzK7hQFA2G9n6U5sZ30R 9Itg== MIME-Version: 1.0 X-Received: by 10.60.47.103 with SMTP id c7mr24403308oen.31.1417186010262; Fri, 28 Nov 2014 06:46:50 -0800 (PST) Received: by 10.60.37.103 with HTTP; Fri, 28 Nov 2014 06:46:50 -0800 (PST) In-Reply-To: <9846323.EvUROnfLfe@rofl> References: <9846323.EvUROnfLfe@rofl> Date: Fri, 28 Nov 2014 15:46:50 +0100 Message-ID: To: Patrick Schaaf Cc: PHP Internals , Sebastian Krebs , Bostjan Skufca Content-Type: multipart/alternative; boundary=001a11c1e918b90c270508ec544b Subject: Re: [PHP-DEV] New function: spl_object_id() or spl_object_handle() From: tyra3l@gmail.com (Ferenc Kovacs) --001a11c1e918b90c270508ec544b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Nov 28, 2014 at 3:02 PM, Patrick Schaaf wrote: > On Friday 28 November 2014 14:51:55 Ferenc Kovacs wrote: > > > > > > I also used spl_object_hash() in the past when traversing/custom > > > serializing object structures which can have infinite recursions betwee= n > > > objects, but even that could be simply solved by storing the already > > > traversed objects in an array (as assigning the objects into another > > > variable doesn't have much overhead) and checking with in_array. > > > > Checking with in_array is O(N) while an array keyed on spl_object_hash() > with the values being the objects, is stable wrt. hash string vs. object > lifetime, and is O(1) on checking for key existence. > > > > The performance difference will become apparent when you have more than a > handful of objects there. > yeah, if you already have the hashmap ready, then calling array_key_exists(spl_object_hash($needle), $haystack) will be much cheaper. but don't forget that for that you have to build the hashmap, eg. you have to call spl_object_hash() for each element, so you can't ignore the cost of that when comparing to the simple in_array solution. from a quick test using spl_object_hash seems to be the slower with big number of elements in haystack. > > BTW, the two or three places where I use spl_object_hash(), in this way, > are exactly your use case: as an "already visited" cache during traversal > of somewhat arbitrary input structure (logging / dumping). > > > > thanks for the feedback! --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --001a11c1e918b90c270508ec544b--