Re: Optimizing php_html_entities()

From: Date: Tue, 23 Jun 2015 14:33:23 +0000
Subject: Re: Optimizing php_html_entities()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-86812@lists.php.net to get a copy of this message
Hey: On Tue, Jun 23, 2015 at 7:37 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> 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 > <?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/

« previous php.internals (#86812) next »