PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
inline test
1 iterations.
strlen($test) took 3.5000000000007E-005 seconds (averaging 3.5000000000007E-005 seconds per iteration)
$test{12} took 1.6999999999934E-005 seconds (averaging 1.6999999999934E-005 seconds per iteration)
function test
1 iterations.
strlen($test) took 4.4000000000044E-005 seconds (averaging 4.4000000000044E-005 seconds per iteration)
$test{12} took 1.3999999999958E-005 seconds (averaging 1.3999999999958E-005 seconds per iteration)
inline test
1,000,000 iterations.
strlen($test) took 1.266645 seconds (averaging 1.266645E-006 seconds per iteration)
$test{12} took 1.785079 seconds (averaging 1.785079E-006 seconds per iteration)
function test
1,000,000 iterations.
strlen($test) took 2.674093 seconds (averaging 2.674093E-006 seconds per iteration)
$test{12} took 2.267316 seconds (averaging 2.267316E-006 seconds per iteration)
Personally, I'd use strlen(), as the logic will make more sense to someone who is not familiar with the code.
uh huh... did you notice that if $password{4} does exist, you get a notice?
Erp. Hmm... must be E_NOTICE. Well, scratch that idea.
EDIT | Actually, I think you may have to use isset() or some other thing that doesn't throw an error when something returns null. Maybe it's E_WARNING. Hmm
Personally, I'd use strlen(), as the logic will make more sense to someone who is not familiar with the code.
inline test
1 iterations.
strlen($test) took 3.599999999998E-005 seconds (averaging 3.599999999998E-005 seconds per iteration)
$test{12} took 4.2999999999987E-005 seconds (averaging 4.2999999999987E-005 seconds per iteration)
function test
1 iterations.
strlen($test) took 2.1999999999994E-005 seconds (averaging 2.1999999999994E-005 seconds per iteration)
$test{12} took 1.5000000000015E-005 seconds (averaging 1.5000000000015E-005 seconds per iteration)
inline test
1,000,000 iterations.
strlen($test) took 1.293642 seconds (averaging 1.293642E-006 seconds per iteration)
$test{12} took 1.777034 seconds (averaging 1.777034E-006 seconds per iteration)
function test
1,000,000 iterations.
strlen($test) took 1.263796 seconds (averaging 1.263796E-006 seconds per iteration)
$test{12} took 1.673452 seconds (averaging 1.673452E-006 seconds per iteration)
switching to isset() doesn't affect the high iteration test much, but does make the single test run three times faster.