ID:               28642
 Comment by:       meyer at labeltools dot com
 Reported By:      am at andremeyer dot name
 Status:           Open
 Bug Type:         Performance problem
 Operating System: Windows XP
 PHP Version:      5.0.3
 New Comment:

In the last paragraph, I meant

ini_set('assert.active', false);

of course. Sorry for the inconvenience.

Best regards
André Meyer
labeltools GmbH


Previous Comments:
------------------------------------------------------------------------

[2005-02-11 15:46:34] am at andremeyer dot name

Well, assertions are not really fast - actually, they are a bottle
neck. I modified my previous script. Look at this:

-----------------------------------------------------------------------------
<?php

$doAsserts = array(true, false);

foreach ($doAsserts as $doAssert)
{
        ini_set('assert.active', $doAssert);            // Turn assertions 
on/off
        $startTime = microtime(true);

        for ($i = -500000; $i < 500000; $i++)
        {
                $result = $i * $i;              // just to have
                assert($result >= 0);
        }

        $endTime = microtime(1);
        $time = $endTime - $startTime;
        print "Elapsed time: $time\r\n";
}

?>
-----------------------------------------------------------------------------

Running this script, I get:

Elapsed time: 1.6357040405273
Elapsed time: 1.6131460666656

Now I comment the line "assert($result >= 0);" so that the script looks
like this:

-----------------------------------------------------------------------------
<?php

$doAsserts = array(true, false);

foreach ($doAsserts as $doAssert)
{
        ini_set('assert.active', $doAssert);            // Turn assertions 
on/off
        $startTime = microtime(true);

        for ($i = -500000; $i < 500000; $i++)
        {
                $result = $i * $i;              // just to have
                //assert($result >= 0);
        }

        $endTime = microtime(1);
        $time = $endTime - $startTime;
        print "Elapsed time: $time\r\n";
}

?>
-----------------------------------------------------------------------------

When I run the script again, I get:

Elapsed time: 0.87688493728638
Elapsed time: 0.87343096733093

As you can see from this, about 50% of the execution time is spent in
the assertion! This would be still acceptable, if I could simply
disable assertions. Well, I can - by ini_set('assert.active', true); -
however, this only disables assertions without affecting the
performance at all. When disabling assertions, any assertion should
rather be considered as not existant (like a comment).
I hope this can be fixed in a future PHP version! Thanks.

------------------------------------------------------------------------

[2005-02-11 15:33:50] [EMAIL PROTECTED]

So, that means that assertions are so fast, that disabling them doesn't
affect script performance. Agree?
But if you change your code in this way:
assert(is_numeric($i));
=>
assert("is_numeric($i)");
you'll get expected results.

------------------------------------------------------------------------

[2004-06-05 16:05:23] am at andremeyer dot name

Description:
------------
Disabling assertions in PHP does not affect performance. After testing
my software with assertions, I want to disable assertions. I do this
with 

ini_set('assert.active', false);

Surprisingly, the assert() statements in my software _still_ consume a
considerable amount of time.


Reproduce code:
---------------
<?php

$doAsserts = array(true, false);

foreach ($doAsserts as $doAssert)
{
        ini_set('assert.active', $doAssert);            // Turn assertions 
on/off
        $startTime = microtime(true);

        for ($i = 0; $i < 1000000; $i++)
                assert(is_numeric($i));

        $endTime = microtime(1);
        $time = $endTime - $startTime;
        print "Elapsed time: $time\r\n";
}

?>


Expected result:
----------------
I expect something like:

Elapsed time: 1.3514750003815 // assertions turned on
Elapsed time: 0.4243453254354 // assertions turned off

I expect the elapsed time to decrease when turning assertions off.


Actual result:
--------------
Elapsed time: 1.3480539321899 // assertions turned on
Elapsed time: 1.3210921287537 // assertions turned off

As you can see, when turning assertions off, the elapsed time is nearly
the same. So I have to comment all my assertions in order to achieve a
better peformance.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=28642&edit=1

Reply via email to