Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86812 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36803 invoked from network); 23 Jun 2015 14:33:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jun 2015 14:33:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=xinchen.h@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.216.50 as permitted sender) X-PHP-List-Original-Sender: xinchen.h@zend.com X-Host-Fingerprint: 209.85.216.50 mail-vn0-f50.google.com Received: from [209.85.216.50] ([209.85.216.50:32857] helo=mail-vn0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/E2-18293-A4E69855 for ; Tue, 23 Jun 2015 10:33:48 -0400 Received: by vnbf190 with SMTP id f190so1811559vnb.0 for ; Tue, 23 Jun 2015 07:33:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=6c0gTjyDFOE7XIbx42aqFiaNkg/GvxwjkuXRguVoKfg=; b=T3VpBzwSNpbT8ameCUhTVbdFJw038VLOY5GPMWdw4T+x97bQTf5E+6OEtGw2MoykbJ h4xnLBA9Lj9VCeMe/6UM0Jf6YtoqPoqBi1vYXSfKnevhtTzEvUxtt3UFczh1KgrkbyoR 7XOPQsfQIF4JIdXddUqIH23CnDFNhV9Do7Gl7ZzEkEjZ/TT0LzQvtEa25kV0/QB4Mp24 DP8NmAEXJkvxBMOCanxGN6yGvu+tXHKv2ms7+pVW+Ie1e+U0rlKZaPr0lLiCrFKYX8pu pcGLim1psxazMzY5oBW80GUq3RObkoDPTZS/nXbSw0F/+miFb85ULkl4DRtD0K91VdIl oZBQ== X-Gm-Message-State: ALoCoQm0RypBNGwGXoBT9SVzJYmrPheztGYozroVoRjAZ7YXMWjaSew2dSmAQ+VXUBLLLW4AbSBuGsfJgYE/FFKlqpq9YSdeOE4r3f4xkTW0BkvaKqHSXzgIhlZbHcvAcj9sykbc0hh2kgTm5cDjVp0AtUEdxW40Z+SkCfobyqt7VFIaGEsmoQA= X-Received: by 10.52.5.2 with SMTP id o2mr31630444vdo.97.1435070023883; Tue, 23 Jun 2015 07:33:43 -0700 (PDT) Received: from mail-vn0-f51.google.com (mail-vn0-f51.google.com. [209.85.216.51]) by mx.google.com with ESMTPSA id s2sm4256704vdh.8.2015.06.23.07.33.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jun 2015 07:33:42 -0700 (PDT) Received: by vnbg129 with SMTP id g129so1795094vnb.9 for ; Tue, 23 Jun 2015 07:33:42 -0700 (PDT) X-Received: by 10.52.30.201 with SMTP id u9mr32062769vdh.95.1435070022374; Tue, 23 Jun 2015 07:33:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.12.1 with HTTP; Tue, 23 Jun 2015 07:33:23 -0700 (PDT) In-Reply-To: References: Date: Tue, 23 Jun 2015 22:33:23 +0800 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Optimizing php_html_entities() From: laruence@php.net (Xinchen Hui) Hey: On Tue, Jun 23, 2015 at 7:37 PM, Yasuo Ohgaki wrote: > Hi all, > > I'm trying to optimize php_html_entities(). > Since htmlspecialchars()/htmlentities() are sensitive function, I would > like to ask comments before merge. > > https://github.com/php/php-src/pull/1356 > > Current php_html_entities() convert int/float/etc to string, then convert > it. > int/float/etc is not required to be escaped. Optimize it by simply > converting them to string. > > Simple benchmark shows about 60% execution time reduction. > > [yohgaki@dev github-php-src]$ ./php-bin b.php > Time: 10.484607934952 > [yohgaki@dev github-php-src]$ ./php-bin b.php > Time: 10.867615222931 > [yohgaki@dev github-php-src]$ ./php.new b.php > Time: 3.9379420280457 > [yohgaki@dev github-php-src]$ ./php.new b.php > Time: 4.0694711208344 > [yohgaki@dev github-php-src]$ cat b.php > const LOOP=100000000; > > $start = microtime(true); > for ($i = 0; $i < LOOP; $i++) { > } > $loop_time = microtime(true) - $start; > > $start = microtime(true); > for ($i = 0; $i < LOOP; $i++) { > htmlspecialchars(123456790); > } > echo 'Time: '.(microtime(true) - $start - $loop_time)."\n"; But passing an non-string to htmlspecialchars are not common used cases.. "optimize" not common used cases... will bring nothing to us.. thanks > > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net -- Xinchen Hui @Laruence http://www.laruence.com/