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

WordPress Trac noreply at wordpress.org
Wed Jun 21 17:34:31 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 spacedmonkey):

 I run the following script using query monitor to start and stop timers.
 Run using PHP 7.4 on docker environment.

 {{{#!php
 add_action('init', function(){
         do_action( 'qm/start', 'strpos' );
         for ($x = 0; $x <= 100000; $x++) {
                 (false === strpos( 'foo-bar', 'bar' ));
         }
         do_action( 'qm/stop', 'strpos' );

         do_action( 'qm/start', 'str_contains' );
         for ($x = 0; $x <= 100000; $x++) {
                 (str_contains( 'foo-bar', 'bar' ));
         }
         do_action( 'qm/stop', 'str_contains' );
 });

 }}}

 strpos - 0.0040
 str_contains - 0.0086.

 Meaning that is str_contains slow, but it is by a very small amount. Not
 so much that this should be a a blocker for this change.

 To be fair, think kind of benchmarking, so not compare to real
 benchmarking of the change in core.

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


More information about the wp-trac mailing list