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.4.2
str_starts_with: 36190251 strpos: 38427320 str_starts_with is faster
Output for 8.4.1
str_starts_with: 36826309 strpos: 39767459 str_starts_with is faster
Output for 8.3.15
str_starts_with: 33612610 strpos: 41979668 str_starts_with is faster
Output for 8.3.14
str_starts_with: 40558993 strpos: 40470114 strpos is faster
Output for 8.3.13
str_starts_with: 38511706 strpos: 48071058 str_starts_with is faster
Output for 8.3.12
str_starts_with: 36008461 strpos: 39352364 str_starts_with is faster
Output for 8.3.11
str_starts_with: 60454618 strpos: 40415050 strpos is faster
Output for 8.3.10
str_starts_with: 34554017 strpos: 41205104 str_starts_with is faster
Output for 8.3.9
str_starts_with: 35080873 strpos: 39857104 str_starts_with is faster
Output for 8.3.8
str_starts_with: 30777850 strpos: 51823976 str_starts_with is faster
Output for 8.3.7
str_starts_with: 55550949 strpos: 80102262 str_starts_with is faster
Output for 8.3.6
str_starts_with: 67164271 strpos: 77580279 str_starts_with is faster
Output for 8.3.5
str_starts_with: 71675703 strpos: 79087875 str_starts_with is faster
Output for 8.3.4
str_starts_with: 57599203 strpos: 73170878 str_starts_with is faster
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.27
str_starts_with: 58061733 strpos: 41096491 strpos is faster
Output for 8.2.26
str_starts_with: 35421023 strpos: 40581898 str_starts_with is faster
Output for 8.2.25
str_starts_with: 34382823 strpos: 40174869 str_starts_with is faster
Output for 8.2.24
str_starts_with: 37228521 strpos: 41558659 str_starts_with is faster
Output for 8.2.23
str_starts_with: 35478269 strpos: 41629810 str_starts_with is faster
Output for 8.2.22
str_starts_with: 40675640 strpos: 41597400 str_starts_with is faster
Output for 8.2.21
str_starts_with: 34419636 strpos: 38343035 str_starts_with is faster
Output for 8.2.20
str_starts_with: 53991616 strpos: 52777493 strpos is faster
Output for 8.2.19
str_starts_with: 63203626 strpos: 80763640 str_starts_with is faster
Output for 8.2.18
str_starts_with: 59079774 strpos: 76447710 str_starts_with is faster
Output for 8.2.17
str_starts_with: 73660592 strpos: 73763136 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.31
str_starts_with: 45865285 strpos: 41871406 strpos is faster
Output for 8.1.30
str_starts_with: 34015090 strpos: 40384292 str_starts_with is faster
Output for 8.1.29
str_starts_with: 40382026 strpos: 52139866 str_starts_with is faster
Output for 8.1.28
str_starts_with: 56182475 strpos: 54061604 strpos is faster
Output for 8.1.27
str_starts_with: 50566097 strpos: 54101149 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
Output for 7.4.29
str_starts_with: 99569380 strpos: 48863757 strpos is faster

preferences:
86.71 ms | 558 KiB | 5 Q