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 8.3.3
str_starts_with: 68544431 strpos: 71659135 str_starts_with is faster
Output for 8.3.2
str_starts_with: 34970377 strpos: 40168010 str_starts_with is faster
Output for 8.3.1
str_starts_with: 33944637 strpos: 43979193 str_starts_with is faster
Output for 8.3.0
str_starts_with: 35400680 strpos: 43838876 str_starts_with is faster
Output for 8.2.16
str_starts_with: 63667017 strpos: 80389352 str_starts_with is faster
Output for 8.2.15
str_starts_with: 35417080 strpos: 42624307 str_starts_with is faster
Output for 8.2.14
str_starts_with: 35082163 strpos: 45441464 str_starts_with is faster
Output for 8.2.13
str_starts_with: 39701693 strpos: 43152818 str_starts_with is faster
Output for 8.2.12
str_starts_with: 37663087 strpos: 40791014 str_starts_with is faster
Output for 8.2.11
str_starts_with: 78449192 strpos: 62780435 strpos is faster
Output for 8.2.10
str_starts_with: 75642230 strpos: 63985708 strpos is faster
Output for 8.2.9
str_starts_with: 54783438 strpos: 62538692 str_starts_with is faster
Output for 8.2.8
str_starts_with: 83416383 strpos: 62653635 strpos is faster
Output for 8.2.7
str_starts_with: 66738428 strpos: 62663900 strpos is faster
Output for 8.2.6
str_starts_with: 48563973 strpos: 61383783 str_starts_with is faster
Output for 8.2.5
str_starts_with: 73382361 strpos: 63276802 strpos is faster
Output for 8.2.4
str_starts_with: 88824998 strpos: 62956761 strpos is faster
Output for 8.2.3
str_starts_with: 80198964 strpos: 62771231 strpos is faster
Output for 8.2.2
str_starts_with: 77045301 strpos: 61752568 strpos is faster
Output for 8.2.1
str_starts_with: 76172779 strpos: 61788243 strpos is faster
Output for 8.2.0
str_starts_with: 77526294 strpos: 62660715 strpos is faster
Output for 8.1.27
str_starts_with: 36235082 strpos: 44987056 str_starts_with is faster
Output for 8.1.26
str_starts_with: 34700714 strpos: 41312728 str_starts_with is faster
Output for 8.1.25
str_starts_with: 35190137 strpos: 39781685 str_starts_with is faster
Output for 8.1.24
str_starts_with: 76780220 strpos: 62015605 strpos is faster
Output for 8.1.23
str_starts_with: 57586493 strpos: 63033005 str_starts_with is faster
Output for 8.1.22
str_starts_with: 57371239 strpos: 61696394 str_starts_with is faster
Output for 8.1.21
str_starts_with: 74932272 strpos: 62155494 strpos is faster
Output for 8.1.20
str_starts_with: 83522222 strpos: 76226919 strpos is faster
Output for 8.1.19
str_starts_with: 58366116 strpos: 64082162 str_starts_with is faster
Output for 8.1.18
str_starts_with: 74195484 strpos: 62304309 strpos is faster
Output for 8.1.17
str_starts_with: 58348880 strpos: 62759704 str_starts_with is faster
Output for 8.1.16
str_starts_with: 80273235 strpos: 62124248 strpos is faster
Output for 8.1.15
str_starts_with: 58057613 strpos: 87980016 str_starts_with is faster
Output for 8.1.14
str_starts_with: 57512483 strpos: 61749174 str_starts_with is faster
Output for 8.1.13
str_starts_with: 72305030 strpos: 62240884 strpos is faster
Output for 8.1.12
str_starts_with: 58167997 strpos: 62330318 str_starts_with is faster
Output for 8.1.11
str_starts_with: 54546592 strpos: 61758737 str_starts_with is faster
Output for 8.1.10
str_starts_with: 73753279 strpos: 64277897 strpos is faster
Output for 8.1.9
str_starts_with: 87146352 strpos: 61643265 strpos is faster
Output for 8.1.8
str_starts_with: 70085492 strpos: 62788458 strpos is faster
Output for 8.1.7
str_starts_with: 86586230 strpos: 64426642 strpos is faster
Output for 8.1.6
str_starts_with: 78431345 strpos: 61915184 strpos is faster
Output for 8.1.5
str_starts_with: 75616421 strpos: 61786178 strpos is faster
Output for 8.1.4
str_starts_with: 91277476 strpos: 68513077 strpos is faster
Output for 8.1.3
str_starts_with: 89144739 strpos: 64057686 strpos is faster
Output for 8.1.2
str_starts_with: 57229475 strpos: 62649468 str_starts_with is faster
Output for 8.1.1
str_starts_with: 85184822 strpos: 65666775 strpos is faster
Output for 8.1.0
str_starts_with: 60565394 strpos: 65076539 str_starts_with is faster
Output for 8.0.30
str_starts_with: 59999602 strpos: 63564634 str_starts_with is faster
Output for 8.0.29
str_starts_with: 61308441 strpos: 62905883 str_starts_with is faster
Output for 8.0.28
str_starts_with: 86017795 strpos: 63992137 strpos is faster
Output for 8.0.27
str_starts_with: 70251732 strpos: 63981781 strpos is faster
Output for 8.0.26
str_starts_with: 89351639 strpos: 62004648 strpos is faster
Output for 8.0.25
str_starts_with: 75258402 strpos: 62045450 strpos is faster
Output for 8.0.24
str_starts_with: 79146390 strpos: 62226201 strpos is faster
Output for 8.0.23
str_starts_with: 60499214 strpos: 64600732 str_starts_with is faster
Output for 8.0.22
str_starts_with: 57409607 strpos: 64039529 str_starts_with is faster
Output for 8.0.21
str_starts_with: 74354392 strpos: 62035605 strpos is faster
Output for 8.0.20
str_starts_with: 66852980 strpos: 61874872 strpos is faster
Output for 8.0.19
str_starts_with: 77231830 strpos: 63712947 strpos is faster
Output for 8.0.18
str_starts_with: 73174098 strpos: 61652588 strpos is faster
Output for 8.0.17
str_starts_with: 81049001 strpos: 61704417 strpos is faster
Output for 8.0.16
str_starts_with: 72529318 strpos: 61836746 strpos is faster
Output for 8.0.15
str_starts_with: 57367103 strpos: 61760802 str_starts_with is faster
Output for 8.0.14
str_starts_with: 71969506 strpos: 61674732 strpos is faster
Output for 8.0.13
str_starts_with: 78610303 strpos: 61801252 strpos is faster
Output for 8.0.12
str_starts_with: 76232218 strpos: 61788823 strpos is faster
Output for 8.0.11
str_starts_with: 73516303 strpos: 61970307 strpos is faster
Output for 8.0.10
str_starts_with: 86916847 strpos: 64315183 strpos is faster
Output for 8.0.9
str_starts_with: 80190251 strpos: 62215685 strpos is faster
Output for 8.0.8
str_starts_with: 82653264 strpos: 63633768 strpos is faster
Output for 8.0.7
str_starts_with: 81124645 strpos: 61853702 strpos is faster
Output for 8.0.6
str_starts_with: 58364693 strpos: 61874242 str_starts_with is faster
Output for 8.0.5
str_starts_with: 84664700 strpos: 62786974 strpos is faster
Output for 8.0.3
str_starts_with: 70870312 strpos: 61685518 strpos is faster
Output for 8.0.2
str_starts_with: 81150544 strpos: 62132420 strpos is faster
Output for 8.0.1
str_starts_with: 60127013 strpos: 64702195 str_starts_with is faster

preferences:
94.12 ms | 402 KiB | 83 Q