mOpened; } function funcAssert() { assert( '$this->isOpen() && $this->mConn' ); $this->mConn++; } function funcIfGuard() { if ( ! ( $this->isOpen() && $this->mConn ) ) { throw new ErrorException( '($this->isOpen() && $this->mConn) does not hold' ); } $this->mConn++; } function testAssert() { for ($i = 1; $i <= ITERATIONS; $i++) { $this->funcAssert(); } } function testIfGuard() { for ($i = 1; $i <= ITERATIONS; $i++) { $this->funcIfGuard(); } } } assert_options( ASSERT_ACTIVE, 0 ); $obj=new ClassA(); $assertTotal=0; $ifGuardTotal=0; for ( $j=0; $j < RUNS ; $j++ ) { $obj->mOpened=true; $obj->mConn=2; $before=microtime(true); $obj->testAssert(); $after=microtime(true); printf("%10s: %04.3f\n", "assert", ($after-$before) ); $assertTotal+=($after-$before); $obj->mOpened=true; $obj->mConn=2; $before=microtime(true); $obj->testIfGuard(); $after=microtime(true); printf("%10s: %04.3f\n", "ifGuard", ($after-$before) ); $ifGuardTotal+=($after-$before); } printf("total: %10s: %03.3f\n", "assert", $assertTotal); printf("total: %10s: %03.3f\n", "ifGuard", $ifGuardTotal); printf("assert is ~%d%% faster than ifGuard\n", (1-($assertTotal/$ifGuardTotal))*100 );