<?php
// Most likely front-end scenario.
function is_admin() {
return true;
}
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_locale_name( $a ) {
return $a;
}
function determine_locale_proposed() {
/**
* 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_locale_name( $_GET['wp_lang'] ) ?: $determined_locale;
} elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
$determined_locale = sanitize_locale_name( $_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 );
}
function determine_locale_proposed_v2() {
/**
* 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 ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
if ( ! empty( $_GET['wp_lang'] ) ) {
$determined_locale = sanitize_locale_name( $_GET['wp_lang'] );
} elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
$determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] );
}
}
if ( ! $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();
}
}
/**
* 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_proposed();
determine_locale_proposed_v2();
$its = 1e5;
$t = hrtime(true);
for ( $i = 0; $i++ < $its; )
determine_locale_proposed();
echo 'proposed : ', $old = ( hrtime(true)-$t ) / 1e9, "s\n";
$t = hrtime(true);
for ( $i = 0; $i++ < $its; )
determine_locale_proposed_v2();
echo 'proposed v2: ', $new = ( hrtime(true)-$t ) / 1e9, "s\n\n";
printf( 'Proposed v2 is %sx faster', number_format( $old / $new, 2 ) );
- Output for 8.4.2
- proposed : 0.017212019s
proposed v2: 0.014765978s
Proposed v2 is 1.17x faster
- Output for 8.4.1
- proposed : 0.00645653s
proposed v2: 0.006701937s
Proposed v2 is 0.96x faster
- Output for 8.3.15
- proposed : 0.007606055s
proposed v2: 0.007402087s
Proposed v2 is 1.03x faster
- Output for 8.3.14
- proposed : 0.015644722s
proposed v2: 0.010741155s
Proposed v2 is 1.46x faster
- Output for 8.3.13
- proposed : 0.013465119s
proposed v2: 0.011746559s
Proposed v2 is 1.15x faster
- Output for 8.3.12
- proposed : 0.0066767s
proposed v2: 0.00668921s
Proposed v2 is 1.00x faster
- Output for 8.3.11
- proposed : 0.006456556s
proposed v2: 0.006609856s
Proposed v2 is 0.98x faster
- Output for 8.3.10
- proposed : 0.007245155s
proposed v2: 0.006920356s
Proposed v2 is 1.05x faster
- Output for 8.3.9
- proposed : 0.006686782s
proposed v2: 0.006871781s
Proposed v2 is 0.97x faster
- Output for 8.3.8
- proposed : 0.008526178s
proposed v2: 0.009983468s
Proposed v2 is 0.85x faster
- Output for 8.3.7
- proposed : 0.013331855s
proposed v2: 0.012385529s
Proposed v2 is 1.08x faster
- Output for 8.3.6
- proposed : 0.012512818s
proposed v2: 0.012698699s
Proposed v2 is 0.99x faster
- Output for 8.3.5
- proposed : 0.017207568s
proposed v2: 0.014088419s
Proposed v2 is 1.22x faster
- Output for 8.3.4
- proposed : 0.012473239s
proposed v2: 0.012710866s
Proposed v2 is 0.98x faster
- Output for 8.3.3
- proposed : 0.013177477s
proposed v2: 0.012526296s
Proposed v2 is 1.05x faster
- Output for 8.3.2
- proposed : 0.006837546s
proposed v2: 0.006956164s
Proposed v2 is 0.98x faster
- Output for 8.3.1
- proposed : 0.006564949s
proposed v2: 0.006815077s
Proposed v2 is 0.96x faster
- Output for 8.3.0
- proposed : 0.006953032s
proposed v2: 0.007501197s
Proposed v2 is 0.93x faster
- Output for 8.2.27
- proposed : 0.015971763s
proposed v2: 0.015479456s
Proposed v2 is 1.03x faster
- Output for 8.2.26
- proposed : 0.012992126s
proposed v2: 0.013247084s
Proposed v2 is 0.98x faster
- Output for 8.2.25
- proposed : 0.00635731s
proposed v2: 0.006526405s
Proposed v2 is 0.97x faster
- Output for 8.2.24
- proposed : 0.006618182s
proposed v2: 0.006689079s
Proposed v2 is 0.99x faster
- Output for 8.2.23
- proposed : 0.006323761s
proposed v2: 0.006666249s
Proposed v2 is 0.95x faster
- Output for 8.2.22
- proposed : 0.006478022s
proposed v2: 0.006709311s
Proposed v2 is 0.97x faster
- Output for 8.2.21
- proposed : 0.013266561s
proposed v2: 0.012816002s
Proposed v2 is 1.04x faster
- Output for 8.2.20
- proposed : 0.009389053s
proposed v2: 0.009550717s
Proposed v2 is 0.98x faster
- Output for 8.2.19
- proposed : 0.016438507s
proposed v2: 0.012598283s
Proposed v2 is 1.30x faster
- Output for 8.2.18
- proposed : 0.014830002s
proposed v2: 0.012506068s
Proposed v2 is 1.19x faster
- Output for 8.2.17
- proposed : 0.016846813s
proposed v2: 0.016741654s
Proposed v2 is 1.01x faster
- Output for 8.2.16
- proposed : 0.012680448s
proposed v2: 0.012783583s
Proposed v2 is 0.99x faster
- Output for 8.2.15
- proposed : 0.006490112s
proposed v2: 0.006563641s
Proposed v2 is 0.99x faster
- Output for 8.2.14
- proposed : 0.006537108s
proposed v2: 0.006581004s
Proposed v2 is 0.99x faster
- Output for 8.2.13
- proposed : 0.007239629s
proposed v2: 0.006701909s
Proposed v2 is 1.08x faster
- Output for 8.2.12
- proposed : 0.006696908s
proposed v2: 0.006950401s
Proposed v2 is 0.96x faster
- Output for 8.2.11
- proposed : 0.010846196s
proposed v2: 0.011331498s
Proposed v2 is 0.96x faster
- Output for 8.2.10
- proposed : 0.00851946s
proposed v2: 0.008897021s
Proposed v2 is 0.96x faster
- Output for 8.2.9
- proposed : 0.008442025s
proposed v2: 0.009172391s
Proposed v2 is 0.92x faster
- Output for 8.2.8
- proposed : 0.008086988s
proposed v2: 0.008783749s
Proposed v2 is 0.92x faster
- Output for 8.2.7
- proposed : 0.00840756s
proposed v2: 0.009046394s
Proposed v2 is 0.93x faster
- Output for 8.2.6
- proposed : 0.008235647s
proposed v2: 0.00875239s
Proposed v2 is 0.94x faster
- Output for 8.2.5
- proposed : 0.00806691s
proposed v2: 0.00900641s
Proposed v2 is 0.90x faster
- Output for 8.2.4
- proposed : 0.008709931s
proposed v2: 0.009120444s
Proposed v2 is 0.95x faster
- Output for 8.2.3
- proposed : 0.009016899s
proposed v2: 0.009512172s
Proposed v2 is 0.95x faster
- Output for 8.2.2
- proposed : 0.008641943s
proposed v2: 0.008886213s
Proposed v2 is 0.97x faster
- Output for 8.2.1
- proposed : 0.008609892s
proposed v2: 0.008679233s
Proposed v2 is 0.99x faster
- Output for 8.2.0
- proposed : 0.008703508s
proposed v2: 0.008749275s
Proposed v2 is 0.99x faster
- Output for 8.1.31
- proposed : 0.01633805s
proposed v2: 0.013936886s
Proposed v2 is 1.17x faster
- Output for 8.1.30
- proposed : 0.00641024s
proposed v2: 0.006806336s
Proposed v2 is 0.94x faster
- Output for 8.1.29
- proposed : 0.008237758s
proposed v2: 0.008748845s
Proposed v2 is 0.94x faster
- Output for 8.1.28
- proposed : 0.01469787s
proposed v2: 0.012203752s
Proposed v2 is 1.20x faster
- Output for 8.1.27
- proposed : 0.006476829s
proposed v2: 0.006688979s
Proposed v2 is 0.97x faster
- Output for 8.1.26
- proposed : 0.006599324s
proposed v2: 0.006779416s
Proposed v2 is 0.97x faster
- Output for 8.1.25
- proposed : 0.006385859s
proposed v2: 0.0066781s
Proposed v2 is 0.96x faster
- Output for 8.1.24
- proposed : 0.019247011s
proposed v2: 0.011427267s
Proposed v2 is 1.68x faster
- Output for 8.1.23
- proposed : 0.007166082s
proposed v2: 0.007514608s
Proposed v2 is 0.95x faster
- Output for 8.1.22
- proposed : 0.007555225s
proposed v2: 0.008607658s
Proposed v2 is 0.88x faster
- Output for 8.1.21
- proposed : 0.007243678s
proposed v2: 0.007865972s
Proposed v2 is 0.92x faster
- Output for 8.1.20
- proposed : 0.007911895s
proposed v2: 0.008478425s
Proposed v2 is 0.93x faster
- Output for 8.1.19
- proposed : 0.008747342s
proposed v2: 0.010397158s
Proposed v2 is 0.84x faster
- Output for 8.1.18
- proposed : 0.007794165s
proposed v2: 0.00846548s
Proposed v2 is 0.92x faster
- Output for 8.1.17
- proposed : 0.008623016s
proposed v2: 0.008511658s
Proposed v2 is 1.01x faster
- Output for 8.1.16
- proposed : 0.007935051s
proposed v2: 0.008452696s
Proposed v2 is 0.94x faster
- Output for 8.1.15
- proposed : 0.007761904s
proposed v2: 0.00810447s
Proposed v2 is 0.96x faster
- Output for 8.1.14
- proposed : 0.007932446s
proposed v2: 0.008345202s
Proposed v2 is 0.95x faster
- Output for 8.1.13
- proposed : 0.008391922s
proposed v2: 0.008915627s
Proposed v2 is 0.94x faster
- Output for 8.1.12
- proposed : 0.008108718s
proposed v2: 0.008241207s
Proposed v2 is 0.98x faster
- Output for 8.1.11
- proposed : 0.007694026s
proposed v2: 0.008284599s
Proposed v2 is 0.93x faster
- Output for 8.1.10
- proposed : 0.007509218s
proposed v2: 0.008356675s
Proposed v2 is 0.90x faster
- Output for 8.1.9
- proposed : 0.008204429s
proposed v2: 0.008474667s
Proposed v2 is 0.97x faster
- Output for 8.1.8
- proposed : 0.008457866s
proposed v2: 0.008140447s
Proposed v2 is 1.04x faster
- Output for 8.1.7
- proposed : 0.008087148s
proposed v2: 0.008475719s
Proposed v2 is 0.95x faster
- Output for 8.1.6
- proposed : 0.007621829s
proposed v2: 0.008297133s
Proposed v2 is 0.92x faster
- Output for 8.1.5
- proposed : 0.007782672s
proposed v2: 0.008592399s
Proposed v2 is 0.91x faster
- Output for 8.1.4
- proposed : 0.007899093s
proposed v2: 0.008474857s
Proposed v2 is 0.93x faster
- Output for 8.1.3
- proposed : 0.007992008s
proposed v2: 0.008730198s
Proposed v2 is 0.92x faster
- Output for 8.1.2
- proposed : 0.00788162s
proposed v2: 0.008673441s
Proposed v2 is 0.91x faster
- Output for 8.1.1
- proposed : 0.008246628s
proposed v2: 0.008566049s
Proposed v2 is 0.96x faster
- Output for 8.1.0
- proposed : 0.008064213s
proposed v2: 0.008791544s
Proposed v2 is 0.92x faster
- Output for 8.0.30
- proposed : 0.008597881s
proposed v2: 0.009354175s
Proposed v2 is 0.92x faster
- Output for 8.0.29
- proposed : 0.009913255s
proposed v2: 0.013354157s
Proposed v2 is 0.74x faster
- Output for 8.0.28
- proposed : 0.010474395s
proposed v2: 0.010324272s
Proposed v2 is 1.01x faster
- Output for 8.0.27
- proposed : 0.00980823s
proposed v2: 0.010311227s
Proposed v2 is 0.95x faster
- Output for 8.0.26
- proposed : 0.010740456s
proposed v2: 0.010019418s
Proposed v2 is 1.07x faster
- Output for 8.0.25
- proposed : 0.010794207s
proposed v2: 0.010228281s
Proposed v2 is 1.06x faster
- Output for 8.0.24
- proposed : 0.010194758s
proposed v2: 0.009827767s
Proposed v2 is 1.04x faster
- Output for 8.0.23
- proposed : 0.010646088s
proposed v2: 0.010167737s
Proposed v2 is 1.05x faster
- Output for 8.0.22
- proposed : 0.010399684s
proposed v2: 0.010149462s
Proposed v2 is 1.02x faster
- Output for 8.0.21
- proposed : 0.009847854s
proposed v2: 0.010004849s
Proposed v2 is 0.98x faster
- Output for 8.0.20
- proposed : 0.010664543s
proposed v2: 0.010341684s
Proposed v2 is 1.03x faster
- Output for 8.0.19
- proposed : 0.011250437s
proposed v2: 0.010608278s
Proposed v2 is 1.06x faster
- Output for 8.0.18
- proposed : 0.011015584s
proposed v2: 0.01033916s
Proposed v2 is 1.07x faster
- Output for 8.0.17
- proposed : 0.010700472s
proposed v2: 0.010207461s
Proposed v2 is 1.05x faster
- Output for 8.0.16
- proposed : 0.012963444s
proposed v2: 0.010356693s
Proposed v2 is 1.25x faster
- Output for 8.0.15
- proposed : 0.010099308s
proposed v2: 0.009667735s
Proposed v2 is 1.04x faster
- Output for 8.0.14
- proposed : 0.009683104s
proposed v2: 0.009762363s
Proposed v2 is 0.99x faster
- Output for 8.0.13
- proposed : 0.010079331s
proposed v2: 0.009663507s
Proposed v2 is 1.04x faster
- Output for 8.0.12
- proposed : 0.009218658s
proposed v2: 0.009346911s
Proposed v2 is 0.99x faster
- Output for 8.0.11
- proposed : 0.010488411s
proposed v2: 0.00969727s
Proposed v2 is 1.08x faster
- Output for 8.0.10
- proposed : 0.009885605s
proposed v2: 0.009952171s
Proposed v2 is 0.99x faster
- Output for 8.0.9
- proposed : 0.00998898s
proposed v2: 0.009547039s
Proposed v2 is 1.05x faster
- Output for 8.0.8
- proposed : 0.010092185s
proposed v2: 0.009606289s
Proposed v2 is 1.05x faster
- Output for 8.0.7
- proposed : 0.009184435s
proposed v2: 0.009651353s
Proposed v2 is 0.95x faster
- Output for 8.0.6
- proposed : 0.009078736s
proposed v2: 0.009922064s
Proposed v2 is 0.92x faster
- Output for 8.0.5
- proposed : 0.009516911s
proposed v2: 0.009964574s
Proposed v2 is 0.96x faster
- Output for 8.0.3
- proposed : 0.009455986s
proposed v2: 0.010029576s
Proposed v2 is 0.94x faster
- Output for 8.0.2
- proposed : 0.010096822s
proposed v2: 0.010283715s
Proposed v2 is 0.98x faster
- Output for 8.0.1
- proposed : 0.00970243s
proposed v2: 0.011639159s
Proposed v2 is 0.83x faster
preferences:
111.08 ms | 559 KiB | 5 Q