php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54249 extra CPU operation on each usage or E_* error types
Submitted: 2011-03-14 18:03 UTC Modified: 2011-03-14 23:49 UTC
From: amrnablus at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.3.5 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
40 - 19 = ?
Subscribe to this entry?

 
 [2011-03-14 18:03 UTC] amrnablus at gmail dot com
Description:
------------
the way the errors are defined in zend_errors.h file makes an extra unneeded cpu shift (multiplication?) operation each time the error constant is used.

clue:
this is is from zend_errors.h:
#define E_ERROR                         (1<<0L)
if you printf( "%d" , E_ERROR ) the pre-processor will replace this line with
printf( "%d" , 1<<0L ) which will cause an uncalled for shit operation

Test script:
---------------
/*
this script will cause a php E_NOTICE to be used, notice the (minor) diff in execution time when error definitions are changed
*/

error_reporting( E_ALL );
for( $i=0 ; $i<10000000; $i++ ) {
        echo $x['a'];
}

Expected result:
----------------
no change to the output is a must


Patches

zend_errors (last revision 2011-03-14 17:03 UTC by amrnablus at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-14 18:31 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-03-14 18:31 UTC] rasmus@php.net
I think you are missing a few pieces here on how compilers work. Yes, there is a 
preprocessor, but there is also a precompiler. The assembly generated by your 
example looks like this:

    movl    $1, %esi
    leaq    LC0(%rip), %rdi
    xorl    %eax, %eax
    leave
    jmp _printf

That says, put 1 into esi, then call printf. That 1 came from 1<<0L. The 
precompiler is smart enough to notice that this is an absolute constant here.
 [2011-03-14 19:44 UTC] Jared dot Williams at ntlworld dot com
See constant folding. http://en.wikipedia.org/wiki/Constant_folding
 [2011-03-14 23:49 UTC] amrnablus at gmail dot com
woops. Thanks guy, my bad.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 30 02:01:25 2020 UTC