[wp-trac] [WordPress Trac] #34525: Use wp_parse_id_list() in the WP_Query class

WordPress Trac noreply at wordpress.org
Sat Oct 31 14:47:46 UTC 2015


#34525: Use wp_parse_id_list() in the WP_Query class
-------------------------+------------------------------
 Reporter:  birgire      |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Query        |     Version:  4.3.1
 Severity:  normal       |  Resolution:
 Keywords:  close        |     Focuses:
-------------------------+------------------------------
Changes (by DrewAPicture):

 * keywords:   => close


Comment:

 Testing strictly against an array of ids and benchmarking the average of
 5,000 iterations, `wp_parse_id_list()` is just slightly slower:

 {{{
 $ids = range( 1000, 2000 );
 array_map( 'absint', array_unique( $ids )

 0.0015718542098999
 0.0015127508163452
 0.0015818600177765
 }}}

 {{{
 $ids = range( 1000, 2000 );
 wp_parse_id_list( $ids );

 0.0016850507736206
 0.0016270678043365
 0.0016728698253632
 }}}

 In addition to the minor performance hit, the main problem I see with this
 is that we'd effectively be adding support for comma-separated ID lists
 for all of these arguments, and I'm not sure that's a rabbit hole we want
 to go down. Even if we made the comma-separated ID list bit in
 `wp_parse_id_list()` optional, it's still slower.

 Side note: It's actually a little puzzling that the current code, which
 runs `array_unique()` on every `array_map()` iteration is actually
 ''faster'' than running the `array_map()` and then `array_unique()` on the
 result as in `wp_parse_id_list()`. PHP, you so silly.

 Benchmarked with:
 {{{#!php
 <?php
 $ids = range( 1000, 2000 );

 $start      = microtime( true );
 $iterations = 5000;

 for ( $i = 0; $i < $iterations; $i++ ) {
         ob_start();
         $list = array_map( 'absint', array_unique( $ids ) );
 //      $list = wp_parse_id_list( $ids );
         ob_get_clean();
 }

 $end = microtime( true ) - $start;
 print( $average = $end / $iterations );
 }}}

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


More information about the wp-trac mailing list