[wp-trac] [WordPress Trac] #58206: Replace usage of strpos with str_contains

WordPress Trac noreply at wordpress.org
Sat Jun 17 08:00:47 UTC 2023


#58206: Replace usage of strpos with str_contains
-------------------------------------+-------------------------------------
 Reporter:  spacedmonkey             |       Owner:  SergeyBiryukov
     Type:  enhancement              |      Status:  assigned
 Priority:  normal                   |   Milestone:  6.3
Component:  General                  |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  good-first-bug has-      |     Focuses:  performance, coding-
  patch 2nd-opinion commit           |  standards
-------------------------------------+-------------------------------------

Comment (by azaozz):

 Replying to [comment:19 mikeschroder]:
 > Is it correct that the test from @azaozz is on the specific function
 being changed, and the one from @spacedmonkey is a holistic / integration
 test that shows the total performance impact, including however often the
 polyfill / new function is used?

 Yes, that's my understanding too. That's why I was surprised to see that
 the results of the "benchmark test" not only missed the slow-down of using
 the polifill vs. using PHP 7.4 native code, but showed the polifill as
 slightly faster.

 > if they’re a slight performance loss, I think this change is worth it

 Yep, agreed. Seems the slowdown when using the polifill is really small.

 > Can you provide more information on how you got these numbers. What
 software or tool was used to generate these numbers? What versions of PHP
 were used, was opcache enabled?

 My testing was really simple: using wp_env (Docker, PHP 7.4), no opcache,
 simple `for ( $i = 0; $i < 100000; $i++ )` loop with time start above and
 echo of passed time below (seems I've deleted the exact code but can
 recreate it if needed).

 That code seems really fast, 100k loops are only ~7ms on my computer.
 Still I'm curious why the tests show different results.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58206#comment:22>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list