<?php
// Most likely front-end scenario.
function is_admin() {
return false;
}
function wp_is_json_request() {
return false;
}
function get_locale() {
return 'en_US';
}
function get_user_locale() {
return 'en_US';
}
function apply_filters( $a, $b ) {
return $b;
}
function sanitize_text_field( $a ) {
return $a;
}
function determine_locale() {
/**
* Filters the locale for the current request prior to the default determination process.
*
* Using this filter allows to override the default logic, effectively short-circuiting the function.
*
* @since 5.0.0
*
* @param string|null $locale The locale to return and short-circuit. Default null.
*/
$determined_locale = apply_filters( 'pre_determine_locale', null );
if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) {
return $determined_locale;
}
$determined_locale = get_locale();
if ( is_admin() ) {
$determined_locale = get_user_locale();
}
if ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) {
$determined_locale = get_user_locale();
}
$wp_lang = '';
if ( ! empty( $_GET['wp_lang'] ) ) {
$wp_lang = sanitize_text_field( $_GET['wp_lang'] );
} elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
$wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] );
}
if ( ! empty( $wp_lang ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
$determined_locale = $wp_lang;
}
/**
* Filters the locale for the current request.
*
* @since 5.0.0
*
* @param string $locale The locale.
*/
return apply_filters( 'determine_locale', $determined_locale );
}
determine_locale();
function determine_locale_new() {
/**
* Filters the locale for the current request prior to the default determination process.
*
* Using this filter allows to override the default logic, effectively short-circuiting the function.
*
* @since 5.0.0
*
* @param string|null $locale The locale to return and short-circuit. Default null.
*/
$determined_locale = apply_filters( 'pre_determine_locale', null );
if ( $determined_locale && is_string( $determined_locale ) ) {
return $determined_locale;
}
if (
is_admin()
|| ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() )
) {
$determined_locale = get_user_locale();
} else {
$determined_locale = get_locale();
}
if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
if ( ! empty( $_GET['wp_lang'] ) ) {
$determined_locale = sanitize_text_field( $_GET['wp_lang'] ) ?: $determined_locale;
} elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
$determined_locale = sanitize_text_field( $_COOKIE['wp_lang'] ) ?: $determined_locale;
}
}
/**
* Filters the locale for the current request.
*
* @since 5.0.0
*
* @param string $locale The locale.
*/
return apply_filters( 'determine_locale', $determined_locale );
}
$its = 1e5;
$t = hrtime(true);
for ( $i = 0; $i++ < $its; )
determine_locale();
echo 'old: ', $old = ( hrtime(true)-$t ) / 1e9, "s\n";
$t = hrtime(true);
for ( $i = 0; $i++ < $its; )
determine_locale_new();
echo 'new: ', $new = ( hrtime(true)-$t ) / 1e9, "s\n\n";
printf( 'New is %sx faster', number_format( $old / $new, 2 ) );
- Output for 8.4.1
- old: 0.022766444s
new: 0.007883062s
New is 2.89x faster
- Output for 8.3.14
- old: 0.011413567s
new: 0.008133972s
New is 1.40x faster
- Output for 8.3.13
- old: 0.01155823s
new: 0.008198853s
New is 1.41x faster
- Output for 8.3.12
- old: 0.011192338s
new: 0.008165112s
New is 1.37x faster
- Output for 8.3.11
- old: 0.011044357s
new: 0.008043308s
New is 1.37x faster
- Output for 8.3.10
- old: 0.011484925s
new: 0.007970984s
New is 1.44x faster
- Output for 8.3.9
- old: 0.011048466s
new: 0.007932491s
New is 1.39x faster
- Output for 8.3.8
- old: 0.015276247s
new: 0.010584884s
New is 1.44x faster
- Output for 8.3.7
- old: 0.024371705s
new: 0.014872345s
New is 1.64x faster
- Output for 8.3.6
- old: 0.026468454s
new: 0.021182406s
New is 1.25x faster
- Output for 8.3.5
- old: 0.030550067s
new: 0.015258328s
New is 2.00x faster
- Output for 8.3.4
- old: 0.022516929s
new: 0.015185244s
New is 1.48x faster
- Output for 8.3.3
- old: 0.021178553s
new: 0.014927608s
New is 1.42x faster
- Output for 8.3.2
- old: 0.011570997s
new: 0.008240516s
New is 1.40x faster
- Output for 8.3.1
- old: 0.022749721s
new: 0.017352029s
New is 1.31x faster
- Output for 8.3.0
- old: 0.013466862s
new: 0.010200903s
New is 1.32x faster
- Output for 8.2.26
- old: 0.011264313s
new: 0.007579511s
New is 1.49x faster
- Output for 8.2.25
- old: 0.026904195s
new: 0.011082259s
New is 2.43x faster
- Output for 8.2.24
- old: 0.011335336s
new: 0.007989168s
New is 1.42x faster
- Output for 8.2.23
- old: 0.011289453s
new: 0.007994s
New is 1.41x faster
- Output for 8.2.22
- old: 0.01176025s
new: 0.007776864s
New is 1.51x faster
- Output for 8.2.21
- old: 0.020018029s
new: 0.008057854s
New is 2.48x faster
- Output for 8.2.20
- old: 0.020771085s
new: 0.013506741s
New is 1.54x faster
- Output for 8.2.19
- old: 0.020774394s
new: 0.014036063s
New is 1.48x faster
- Output for 8.2.18
- old: 0.026259983s
new: 0.016003716s
New is 1.64x faster
- Output for 8.2.17
- old: 0.03104046s
new: 0.016361645s
New is 1.90x faster
- Output for 8.2.16
- old: 0.021719557s
new: 0.015699707s
New is 1.38x faster
- Output for 8.2.15
- old: 0.019520228s
new: 0.007839721s
New is 2.49x faster
- Output for 8.2.14
- old: 0.01163472s
new: 0.008407928s
New is 1.38x faster
- Output for 8.2.13
- old: 0.011696066s
new: 0.008126372s
New is 1.44x faster
- Output for 8.2.12
- old: 0.013606841s
new: 0.009621862s
New is 1.41x faster
- Output for 8.2.11
- old: 0.022239061s
new: 0.014423868s
New is 1.54x faster
- Output for 8.2.10
- old: 0.016645091s
new: 0.010939114s
New is 1.52x faster
- Output for 8.2.9
- old: 0.017163367s
new: 0.010788555s
New is 1.59x faster
- Output for 8.2.8
- old: 0.015837644s
new: 0.010569798s
New is 1.50x faster
- Output for 8.2.7
- old: 0.016682107s
new: 0.011001185s
New is 1.52x faster
- Output for 8.2.6
- old: 0.018794477s
new: 0.012315235s
New is 1.53x faster
- Output for 8.2.5
- old: 0.01765483s
new: 0.013067043s
New is 1.35x faster
- Output for 8.2.4
- old: 0.021245208s
new: 0.011196716s
New is 1.90x faster
- Output for 8.2.3
- old: 0.017984551s
new: 0.011365965s
New is 1.58x faster
- Output for 8.2.2
- old: 0.021438562s
new: 0.0126577s
New is 1.69x faster
- Output for 8.2.1
- old: 0.017277949s
new: 0.011276738s
New is 1.53x faster
- Output for 8.2.0
- old: 0.016482481s
new: 0.011202297s
New is 1.47x faster
- Output for 8.1.31
- old: 0.025715417s
new: 0.017354959s
New is 1.48x faster
- Output for 8.1.30
- old: 0.011362933s
new: 0.008055468s
New is 1.41x faster
- Output for 8.1.29
- old: 0.023130391s
new: 0.012924696s
New is 1.79x faster
- Output for 8.1.28
- old: 0.020581559s
new: 0.015911116s
New is 1.29x faster
- Output for 8.1.27
- old: 0.011947408s
new: 0.008150317s
New is 1.47x faster
- Output for 8.1.26
- old: 0.0116978s
new: 0.008261273s
New is 1.42x faster
- Output for 8.1.25
- old: 0.011534022s
new: 0.008107328s
New is 1.42x faster
- Output for 8.1.24
- old: 0.022074428s
new: 0.014498805s
New is 1.52x faster
- Output for 8.1.23
- old: 0.0140101s
new: 0.009180153s
New is 1.53x faster
- Output for 8.1.22
- old: 0.0158876s
new: 0.010482023s
New is 1.52x faster
- Output for 8.1.21
- old: 0.014381689s
new: 0.009457891s
New is 1.52x faster
- Output for 8.1.20
- old: 0.015731717s
new: 0.010236867s
New is 1.54x faster
- Output for 8.1.19
- old: 0.017443402s
new: 0.010204175s
New is 1.71x faster
- Output for 8.1.18
- old: 0.016575765s
new: 0.010996839s
New is 1.51x faster
- Output for 8.1.17
- old: 0.016159281s
new: 0.010682317s
New is 1.51x faster
- Output for 8.1.16
- old: 0.015339605s
new: 0.010261554s
New is 1.49x faster
- Output for 8.1.15
- old: 0.015393197s
new: 0.010070713s
New is 1.53x faster
- Output for 8.1.14
- old: 0.015616799s
new: 0.01056726s
New is 1.48x faster
- Output for 8.1.13
- old: 0.015015825s
new: 0.010404664s
New is 1.44x faster
- Output for 8.1.12
- old: 0.01616978s
new: 0.010172587s
New is 1.59x faster
- Output for 8.1.11
- old: 0.015485971s
new: 0.010533696s
New is 1.47x faster
- Output for 8.1.10
- old: 0.015732967s
new: 0.010303853s
New is 1.53x faster
- Output for 8.1.9
- old: 0.015232383s
new: 0.010533476s
New is 1.45x faster
- Output for 8.1.8
- old: 0.015337702s
new: 0.010009709s
New is 1.53x faster
- Output for 8.1.7
- old: 0.015538811s
new: 0.010083819s
New is 1.54x faster
- Output for 8.1.6
- old: 0.016156245s
new: 0.010581837s
New is 1.53x faster
- Output for 8.1.5
- old: 0.014846897s
new: 0.01033894s
New is 1.44x faster
- Output for 8.1.4
- old: 0.015387847s
new: 0.010120517s
New is 1.52x faster
- Output for 8.1.3
- old: 0.016040426s
new: 0.010561139s
New is 1.52x faster
- Output for 8.1.2
- old: 0.016003657s
new: 0.010881212s
New is 1.47x faster
- Output for 8.1.1
- old: 0.015907415s
new: 0.012140166s
New is 1.31x faster
- Output for 8.1.0
- old: 0.015963271s
new: 0.011446387s
New is 1.39x faster
- Output for 8.0.30
- old: 0.014618894s
new: 0.01061164s
New is 1.38x faster
- Output for 8.0.29
- old: 0.016508057s
new: 0.011233999s
New is 1.47x faster
- Output for 8.0.28
- old: 0.016144214s
new: 0.011528211s
New is 1.40x faster
- Output for 8.0.27
- old: 0.016358396s
new: 0.011891175s
New is 1.38x faster
- Output for 8.0.26
- old: 0.017450113s
new: 0.012946455s
New is 1.35x faster
- Output for 8.0.25
- old: 0.016685793s
new: 0.011330529s
New is 1.47x faster
- Output for 8.0.24
- old: 0.019414027s
new: 0.011252261s
New is 1.73x faster
- Output for 8.0.23
- old: 0.017378679s
new: 0.011452539s
New is 1.52x faster
- Output for 8.0.22
- old: 0.017737144s
new: 0.012122431s
New is 1.46x faster
- Output for 8.0.21
- old: 0.016709448s
new: 0.011524704s
New is 1.45x faster
- Output for 8.0.20
- old: 0.017814942s
new: 0.012335502s
New is 1.44x faster
- Output for 8.0.19
- old: 0.017691159s
new: 0.012011281s
New is 1.47x faster
- Output for 8.0.18
- old: 0.017594356s
new: 0.012048643s
New is 1.46x faster
- Output for 8.0.17
- old: 0.016765935s
new: 0.01172979s
New is 1.43x faster
- Output for 8.0.16
- old: 0.01701308s
new: 0.012069892s
New is 1.41x faster
- Output for 8.0.15
- old: 0.015542128s
new: 0.011332271s
New is 1.37x faster
- Output for 8.0.14
- old: 0.016036899s
new: 0.010822631s
New is 1.48x faster
- Output for 8.0.13
- old: 0.016494904s
new: 0.010951474s
New is 1.51x faster
- Output for 8.0.12
- old: 0.016203704s
new: 0.01055693s
New is 1.53x faster
- Output for 8.0.11
- old: 0.015643288s
new: 0.011472616s
New is 1.36x faster
- Output for 8.0.10
- old: 0.01730942s
new: 0.011742695s
New is 1.47x faster
- Output for 8.0.9
- old: 0.016538125s
new: 0.011014232s
New is 1.50x faster
- Output for 8.0.8
- old: 0.01665265s
new: 0.011159507s
New is 1.49x faster
- Output for 8.0.7
- old: 0.016109015s
new: 0.011374761s
New is 1.42x faster
- Output for 8.0.6
- old: 0.015340217s
new: 0.011430627s
New is 1.34x faster
- Output for 8.0.5
- old: 0.015571502s
new: 0.010983836s
New is 1.42x faster
- Output for 8.0.3
- old: 0.015084756s
new: 0.011333485s
New is 1.33x faster
- Output for 8.0.2
- old: 0.016693998s
new: 0.011226953s
New is 1.49x faster
- Output for 8.0.1
- old: 0.015768323s
new: 0.011610566s
New is 1.36x faster
preferences:
95.16 ms | 553 KiB | 5 Q