3v4l.org

run code in 300+ PHP versions simultaneously
<?php if ( ! function_exists( 'str_starts_with' ) ) { function str_starts_with( $haystack, $needle ) { if ( '' === $needle ) { return true; } return 0 === strpos( $haystack, $needle ); } } $string = 'abcdefghijklmnopqrstuvwxyz'; $start = hrtime(true); for ( $i = 0; $i < 1000000; $i++ ) { $result1 = str_starts_with( $string, 'abc' ); $result2 = str_starts_with( $string, 'abd' ); } $end = hrtime(true); $str_starts_with_time = $end - $start; $start = hrtime(true); for ( $i = 0; $i < 1000000; $i++ ) { $result1 = 0 === strpos( $string, 'abc' ); $result2 = 0 === strpos( $string, 'abd' ); } $end = hrtime(true); $strpos_time = $end - $start; echo 'str_starts_with: ' . $str_starts_with_time . PHP_EOL; echo 'strpos: ' . $strpos_time . PHP_EOL; // echo which function is faster if ( $str_starts_with_time < $strpos_time ) { echo 'str_starts_with is faster' . PHP_EOL; } else { echo 'strpos is faster' . PHP_EOL; }
Output for git.master
str_starts_with: 74871561 strpos: 61657967 strpos is faster
Output for git.master_jit
str_starts_with: 73832587 strpos: 71354651 strpos is faster
Output for rfc.property-hooks
str_starts_with: 34524678 strpos: 40422826 str_starts_with is faster

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
30.9 ms | 407 KiB | 5 Q