|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
Patcheszend_errors (last revision 2011-03-14 17:03 UTC by amrnablus at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 17:00:02 2025 UTC |
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.