<?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_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.012640557s
new: 0.007120859s
New is 1.78x faster
- Output for 8.3.14
- old: 0.024836651s
new: 0.013039224s
New is 1.90x faster
- Output for 8.3.13
- old: 0.012455583s
new: 0.006616595s
New is 1.88x faster
- Output for 8.3.12
- old: 0.014634127s
new: 0.007686676s
New is 1.90x faster
- Output for 8.3.11
- old: 0.014142326s
new: 0.006444382s
New is 2.19x faster
- Output for 8.3.10
- old: 0.012010368s
new: 0.006386219s
New is 1.88x faster
- Output for 8.3.9
- old: 0.012999124s
new: 0.006827461s
New is 1.90x faster
- Output for 8.3.8
- old: 0.027624933s
new: 0.011264476s
New is 2.45x faster
- Output for 8.3.7
- old: 0.02254561s
new: 0.01223473s
New is 1.84x faster
- Output for 8.3.6
- old: 0.03176087s
new: 0.012846372s
New is 2.47x faster
- Output for 8.3.5
- old: 0.02789412s
new: 0.015480596s
New is 1.80x faster
- Output for 8.3.4
- old: 0.023272777s
new: 0.01200986s
New is 1.94x faster
- Output for 8.3.3
- old: 0.024852221s
new: 0.012457742s
New is 1.99x faster
- Output for 8.3.2
- old: 0.018901885s
new: 0.006606638s
New is 2.86x faster
- Output for 8.3.1
- old: 0.012396344s
new: 0.00663825s
New is 1.87x faster
- Output for 8.3.0
- old: 0.01265494s
new: 0.006766581s
New is 1.87x faster
- Output for 8.2.26
- old: 0.011609305s
new: 0.006265393s
New is 1.85x faster
- Output for 8.2.25
- old: 0.012281448s
new: 0.006302331s
New is 1.95x faster
- Output for 8.2.24
- old: 0.012453333s
new: 0.006419629s
New is 1.94x faster
- Output for 8.2.23
- old: 0.02383706s
new: 0.010371736s
New is 2.30x faster
- Output for 8.2.22
- old: 0.012159837s
new: 0.006454273s
New is 1.88x faster
- Output for 8.2.21
- old: 0.026018174s
new: 0.018177271s
New is 1.43x faster
- Output for 8.2.20
- old: 0.016862974s
new: 0.008429158s
New is 2.00x faster
- Output for 8.2.19
- old: 0.034087048s
new: 0.01685545s
New is 2.02x faster
- Output for 8.2.18
- old: 0.022414465s
new: 0.011578227s
New is 1.94x faster
- Output for 8.2.17
- old: 0.028489292s
new: 0.013008553s
New is 2.19x faster
- Output for 8.2.16
- old: 0.024477428s
new: 0.012334883s
New is 1.98x faster
- Output for 8.2.15
- old: 0.024888663s
new: 0.00648956s
New is 3.84x faster
- Output for 8.2.14
- old: 0.012248376s
new: 0.006888909s
New is 1.78x faster
- Output for 8.2.13
- old: 0.012244861s
new: 0.006615227s
New is 1.85x faster
- Output for 8.2.12
- old: 0.013068641s
new: 0.007202881s
New is 1.81x faster
- Output for 8.2.11
- old: 0.023726394s
new: 0.01067943s
New is 2.22x faster
- Output for 8.2.10
- old: 0.018027618s
new: 0.008188286s
New is 2.20x faster
- Output for 8.2.9
- old: 0.024642719s
new: 0.01050316s
New is 2.35x faster
- Output for 8.2.8
- old: 0.022212858s
new: 0.008748365s
New is 2.54x faster
- Output for 8.2.7
- old: 0.017907756s
new: 0.008220036s
New is 2.18x faster
- Output for 8.2.6
- old: 0.018606252s
new: 0.008595923s
New is 2.16x faster
- Output for 8.2.5
- old: 0.017877209s
new: 0.008102032s
New is 2.21x faster
- Output for 8.2.4
- old: 0.017686489s
new: 0.008531512s
New is 2.07x faster
- Output for 8.2.3
- old: 0.019127836s
new: 0.008348988s
New is 2.29x faster
- Output for 8.2.2
- old: 0.01737403s
new: 0.008130316s
New is 2.14x faster
- Output for 8.2.1
- old: 0.01833427s
new: 0.008601564s
New is 2.13x faster
- Output for 8.2.0
- old: 0.018430601s
new: 0.009950076s
New is 1.85x faster
- Output for 8.1.31
- old: 0.013517405s
new: 0.006395512s
New is 2.11x faster
- Output for 8.1.30
- old: 0.011912265s
new: 0.006282113s
New is 1.90x faster
- Output for 8.1.29
- old: 0.016099515s
new: 0.008613683s
New is 1.87x faster
- Output for 8.1.28
- old: 0.027317657s
new: 0.014453126s
New is 1.89x faster
- Output for 8.1.27
- old: 0.012575918s
new: 0.006524605s
New is 1.93x faster
- Output for 8.1.26
- old: 0.012743513s
new: 0.006650748s
New is 1.92x faster
- Output for 8.1.25
- old: 0.012134356s
new: 0.006684285s
New is 1.82x faster
- Output for 8.1.24
- old: 0.024044689s
new: 0.010895979s
New is 2.21x faster
- Output for 8.1.23
- old: 0.015230517s
new: 0.007137099s
New is 2.13x faster
- Output for 8.1.22
- old: 0.017028869s
new: 0.007679898s
New is 2.22x faster
- Output for 8.1.21
- old: 0.016975154s
new: 0.007648351s
New is 2.22x faster
- Output for 8.1.20
- old: 0.017107431s
new: 0.007695817s
New is 2.22x faster
- Output for 8.1.19
- old: 0.020746737s
new: 0.01106662s
New is 1.87x faster
- Output for 8.1.18
- old: 0.018231616s
new: 0.007993127s
New is 2.28x faster
- Output for 8.1.17
- old: 0.017603011s
new: 0.008105689s
New is 2.17x faster
- Output for 8.1.16
- old: 0.016284776s
new: 0.007911433s
New is 2.06x faster
- Output for 8.1.15
- old: 0.016084319s
new: 0.007734108s
New is 2.08x faster
- Output for 8.1.14
- old: 0.016654864s
new: 0.007882158s
New is 2.11x faster
- Output for 8.1.13
- old: 0.016214343s
new: 0.008314512s
New is 1.95x faster
- Output for 8.1.12
- old: 0.017362387s
new: 0.007998818s
New is 2.17x faster
- Output for 8.1.11
- old: 0.016596744s
new: 0.007889431s
New is 2.10x faster
- Output for 8.1.10
- old: 0.016950972s
new: 0.007551855s
New is 2.24x faster
- Output for 8.1.9
- old: 0.016329541s
new: 0.008413499s
New is 1.94x faster
- Output for 8.1.8
- old: 0.016423288s
new: 0.007874774s
New is 2.09x faster
- Output for 8.1.7
- old: 0.018081353s
new: 0.008181591s
New is 2.21x faster
- Output for 8.1.6
- old: 0.017054747s
new: 0.007588586s
New is 2.25x faster
- Output for 8.1.5
- old: 0.016109756s
new: 0.00778256s
New is 2.07x faster
- Output for 8.1.4
- old: 0.016749903s
new: 0.007855226s
New is 2.13x faster
- Output for 8.1.3
- old: 0.016803344s
new: 0.007642326s
New is 2.20x faster
- Output for 8.1.2
- old: 0.017488265s
new: 0.008182384s
New is 2.14x faster
- Output for 8.1.1
- old: 0.016915745s
new: 0.008209835s
New is 2.06x faster
- Output for 8.1.0
- old: 0.017197366s
new: 0.008103555s
New is 2.12x faster
- Output for 8.0.30
- old: 0.01599284s
new: 0.008581909s
New is 1.86x faster
- Output for 8.0.29
- old: 0.017582144s
new: 0.009246047s
New is 1.90x faster
- Output for 8.0.28
- old: 0.018018825s
new: 0.009698882s
New is 1.86x faster
- Output for 8.0.27
- old: 0.018426233s
new: 0.009772491s
New is 1.89x faster
- Output for 8.0.26
- old: 0.018326755s
new: 0.009662724s
New is 1.90x faster
- Output for 8.0.25
- old: 0.018529808s
new: 0.009310681s
New is 1.99x faster
- Output for 8.0.24
- old: 0.018842066s
new: 0.009120992s
New is 2.07x faster
- Output for 8.0.23
- old: 0.017721585s
new: 0.00937412s
New is 1.89x faster
- Output for 8.0.22
- old: 0.018394624s
new: 0.009884862s
New is 1.86x faster
- Output for 8.0.21
- old: 0.017711015s
new: 0.009791536s
New is 1.81x faster
- Output for 8.0.20
- old: 0.018860311s
new: 0.010130425s
New is 1.86x faster
- Output for 8.0.19
- old: 0.019308816s
new: 0.010200157s
New is 1.89x faster
- Output for 8.0.18
- old: 0.018707082s
new: 0.009675108s
New is 1.93x faster
- Output for 8.0.17
- old: 0.01831837s
new: 0.009562536s
New is 1.92x faster
- Output for 8.0.16
- old: 0.017540874s
new: 0.009584887s
New is 1.83x faster
- Output for 8.0.15
- old: 0.017266818s
new: 0.009327352s
New is 1.85x faster
- Output for 8.0.14
- old: 0.017105264s
new: 0.008646499s
New is 1.98x faster
- Output for 8.0.13
- old: 0.017558296s
new: 0.008907151s
New is 1.97x faster
- Output for 8.0.12
- old: 0.016950051s
new: 0.008621792s
New is 1.97x faster
- Output for 8.0.11
- old: 0.017243884s
new: 0.009137675s
New is 1.89x faster
- Output for 8.0.10
- old: 0.019101886s
new: 0.00893331s
New is 2.14x faster
- Output for 8.0.9
- old: 0.018189586s
new: 0.00904521s
New is 2.01x faster
- Output for 8.0.8
- old: 0.01767703s
new: 0.00949648s
New is 1.86x faster
- Output for 8.0.7
- old: 0.016641058s
new: 0.00916185s
New is 1.82x faster
- Output for 8.0.6
- old: 0.016653121s
new: 0.00913538s
New is 1.82x faster
- Output for 8.0.5
- old: 0.016319922s
new: 0.009354052s
New is 1.74x faster
- Output for 8.0.3
- old: 0.016552751s
new: 0.009438241s
New is 1.75x faster
- Output for 8.0.2
- old: 0.01839327s
new: 0.009796887s
New is 1.88x faster
- Output for 8.0.1
- old: 0.017146941s
new: 0.009364182s
New is 1.83x faster
preferences:
87.39 ms | 552 KiB | 5 Q