This function is astonishingly fast, I think you should always use it.
See my test code below, uncomment specific lines and run it yourself to see the effect.
<?php
$str = sha1( '0' ); // b6589fc6ab0dc82cf12099d1c2d40ab994e8410c
$results = [];
for ( $j = 0; $j < 100; ++ $j ) {
$time = microtime( true );
for ( $i = 0; $i < 999999; ++ $i )
// if ( 'b6589f' === substr( $str, 0, 6 ) ); # 0.53781658887863
// if ( 'abcdef' === substr( $str, 0, 6 ) ); # 0.54560388565063
// if ( 0 === strpos( $str, 'b6589f' ) ); # 0.48515980958939
// if ( 0 === strpos( $str, 'abcdef' ) ); # 0.53281677722931
// if ( str_starts_with( $str, 'b6589f' ) ); # 0.29601020097733
// if ( str_starts_with( $str, 'abcdef' ) ); # 0.30969516038895
// if (
// 'b' === $str[0] && '6' === $str[1] && '5' === $str[2] &&
// '8' === $str[3] && '9' === $str[4] && 'f' === $str[5]
// ); # 1.6171971583366
$results[] = microtime( true ) - $time;
}
echo array_sum( $results ) / 100;