[wp-trac] [WordPress Trac] #43891: Performance improvement for WP_Query
WordPress Trac
noreply at wordpress.org
Sun Apr 29 05:02:24 UTC 2018
#43891: Performance improvement for WP_Query
-------------------------------------------------+-------------------------
Reporter: rnaby | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Query | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-testing reporter- | Focuses:
feedback |
-------------------------------------------------+-------------------------
Comment (by rnaby):
Yes @johnbillion . I tried putting the `judge` functions one above another
and the results are pretty similar. Please have a look at the screenshot.
[[Image(https://raw.githubusercontent.com/rnaby/screenshots/master/Screenshot-2018-04-29-10%3A44%3A20-001.png)]]
Here is the testing script-
{{{
<?php
function _reset( $array ) {
return reset($array);
}
function _foreach( $array ) {
foreach( $array as $el ) {
return $el;
}
}
function judge($array, $method) {
$loop = 10000;
$time = microtime(true);
for ($i = 0; $i < $loop; ++$i) {
$temp = $method($array);
}
$time = microtime(true) - $time;
echo implode(PHP_EOL, [
$method.':',
" Time: {$time}s",
" Result: {$temp}",
'',
'',
]);
}
$a = [];
$index = 0;
for ($i = 0; $i < 10000; ++$i) {
$index += rand(1, 5);
$a[$index] = substr(md5(rand()), 0, rand(3, 7));
}
judge($a, '_foreach');
judge($a, '_reset');
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43891#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list