[wp-trac] [WordPress Trac] #32077: get_pages re-factor to reduce line-count, DRY up code & give more specific functions for some of it's main processes

WordPress Trac noreply at wordpress.org
Thu Apr 23 19:51:17 UTC 2015


#32077: get_pages re-factor to reduce line-count, DRY up code & give more specific
functions for some of it's main processes
------------------------------------------+--------------------------------
 Reporter:  LewisCowles                   |       Owner:
     Type:  enhancement                   |      Status:  new
 Priority:  normal                        |   Milestone:  Awaiting Review
Component:  Posts, Post Types             |     Version:  1.5
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:  docs, performance
------------------------------------------+--------------------------------

Comment (by LewisCowles):

 > We generally avoid refactoring for refactoring's sake.

 limited data from functions

 Old function
 0.044784545898438MB RAM used    0ms running time
 0.011528015136719MB RAM used    0ms running time

 New function
 0.0069198608398438MB RAM used   1ms running time        1/1000th of a
 second approx
 0.005706787109375MB RAM used    0ms running time

 So it uses less RAM, and represents maybe 1ms time per unique-call...

 If anyone else wants to formally benchmark

 function start
     $rustart = getrusage();
     $start_memory = memory_get_usage();

 all function exits (replaced return with below + trailing return)
     $ruend = getrusage();
     echo "\r\n" . ( ( memory_get_usage() - $start_memory) / 1024 / 1024 )
 . "MB RAM used\r\n";
     echo "\r\n" . ( ($ruend["ru_utime.tv_sec"]*1000 +
 intval($ruend["ru_utime.tv_usec"]/1000)) -
 ($rustart["ru_utime.tv_sec"]*1000 +
 intval($rustart["ru_utime.tv_usec"]/1000)) ) . "ms running time\r\n";

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


More information about the wp-trac mailing list