Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64495 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12014 invoked from network); 3 Jan 2013 10:40:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2013 10:40:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:37089] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/35-35624-32065E05 for ; Thu, 03 Jan 2013 05:40:37 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 2EC1E70003D9 for ; Thu, 3 Jan 2013 10:40:32 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id uolWLHFs29Rh for ; Thu, 3 Jan 2013 10:40:31 +0000 (WET) Received: from nebm.ist.utl.pt (unknown [IPv6:2001:690:2100:4::58:1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id CB5B670003D4 for ; Thu, 3 Jan 2013 10:40:31 +0000 (WET) Received: from localhost ([127.0.0.1] helo=nebm.ist.utl.pt) by nebm.ist.utl.pt with esmtp (Exim 4.72) (envelope-from ) id 1TqiDv-0004Qu-LZ for internals@lists.php.net; Thu, 03 Jan 2013 10:40:31 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 03 Jan 2013 11:40:31 +0100 To: Organization: =?UTF-8?Q?N=C3=BAcleo_de_Engenharia_Biom=C3=A9dica_do_Insti?= =?UTF-8?Q?tuto_Superior_T=C3=A9cnico?= In-Reply-To: References: Message-ID: X-Sender: glopes@nebm.ist.utl.pt User-Agent: RoundCube Webmail/0.8-rc Subject: Re: [PHP-DEV] strtr vs. =?UTF-8?Q?str=5Freplace=20runtime?= From: glopes@nebm.ist.utl.pt (Gustavo Lopes) Em 2013-01-02 16:53, Nicolai Scheer escreveu: > > I might have chosen the wrong tool for what I'm trying to achieve in > the > first place, but can anyone comment on the algorithmic complexity of > strtr? > This is definitely not the expected behaviour for such small inputs. > Since > the inputs varied and the keys where determined automatically in my > original script, I was confronted with runtimes of several hours > compared > to just a few seconds with str_replace. > > If this is the expected behaviour, at least the documentation should > be > adjusted to state that this function is very inefficient with > keylengths > that are very distant from each other... > Please open a bug to track this. The algorithm behaves very poorly in this case because at each position of the text, all the substrings starting there and with size between m and n (where m is the size of the smallest pattern and n is the largest) are checked, even if there are only two patterns with size m and n. We could fix this easily by building a set of the pattern sizes found and try only with those. The hashing of the substrings could also be improved; we don't have to recalculate everything when we advance in the text. -- Gustavo Lopes