On Tue, Jun 23, 2015 at 10:33 AM, Xinchen Hui <larue...@php.net> wrote:
> Hey:
>
> On Tue, Jun 23, 2015 at 7:37 PM, Yasuo Ohgaki <yohg...@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..

In addition, this breaks the contract, specifically when using scalar
types. Because you're no longer going to error when the contract is
broken (considering htmlspecialchars is documented as string:string).

Anthony

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to