@ 2023-05-15T12:40:45Z <?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 ) );
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.4.1 0.010 0.019 22.13 8.3.14 0.010 0.044 17.27 8.3.13 0.007 0.020 18.28 8.3.12 0.007 0.027 19.16 8.3.11 0.006 0.029 20.94 8.3.10 0.006 0.022 24.06 8.3.9 0.000 0.028 26.77 8.3.8 0.003 0.049 18.15 8.3.7 0.003 0.050 16.75 8.3.6 0.014 0.051 18.24 8.3.5 0.003 0.059 16.74 8.3.4 0.007 0.044 23.79 8.3.3 0.007 0.046 18.80 8.3.2 0.003 0.036 24.18 8.3.1 0.007 0.021 24.66 8.3.0 0.009 0.018 26.16 8.2.26 0.007 0.020 18.96 8.2.25 0.013 0.019 18.27 8.2.24 0.007 0.020 18.88 8.2.23 0.007 0.042 22.58 8.2.22 0.000 0.028 37.54 8.2.21 0.007 0.053 26.77 8.2.20 0.010 0.026 16.63 8.2.19 0.010 0.062 16.58 8.2.18 0.013 0.036 16.50 8.2.17 0.013 0.046 19.09 8.2.16 0.013 0.039 22.96 8.2.15 0.016 0.032 25.66 8.2.14 0.012 0.015 24.66 8.2.13 0.003 0.023 26.16 8.2.12 0.007 0.024 17.91 8.2.11 0.003 0.040 22.38 8.2.10 0.007 0.031 17.72 8.2.9 0.010 0.036 19.20 8.2.8 0.009 0.030 17.97 8.2.7 0.000 0.034 17.75 8.2.6 0.014 0.034 17.75 8.2.5 0.014 0.032 17.63 8.2.4 0.019 0.026 17.63 8.2.3 0.010 0.038 17.38 8.2.2 0.007 0.036 17.50 8.2.1 0.004 0.040 17.50 8.2.0 0.015 0.030 17.50 8.1.31 0.003 0.026 16.41 8.1.30 0.000 0.027 17.67 8.1.29 0.006 0.028 18.88 8.1.28 0.020 0.040 25.92 8.1.27 0.000 0.027 23.96 8.1.26 0.003 0.024 26.35 8.1.25 0.007 0.020 28.09 8.1.24 0.003 0.044 22.16 8.1.23 0.010 0.024 22.66 8.1.22 0.006 0.026 17.91 8.1.21 0.003 0.029 18.77 8.1.20 0.000 0.033 17.23 8.1.19 0.015 0.034 16.98 8.1.18 0.015 0.030 17.25 8.1.17 0.007 0.037 16.97 8.1.16 0.013 0.029 17.38 8.1.15 0.004 0.037 17.13 8.1.14 0.016 0.026 17.25 8.1.13 0.008 0.034 17.21 8.1.12 0.007 0.036 17.22 8.1.11 0.015 0.029 17.36 8.1.10 0.011 0.030 17.47 8.1.9 0.007 0.034 17.38 8.1.8 0.015 0.030 17.11 8.1.7 0.017 0.028 17.13 8.1.6 0.009 0.033 17.50 8.1.5 0.019 0.022 17.34 8.1.4 0.017 0.026 17.38 8.1.3 0.018 0.027 17.35 8.1.2 0.007 0.037 17.50 8.1.1 0.007 0.036 17.22 8.1.0 0.020 0.023 17.38 8.0.30 0.000 0.033 19.87 8.0.29 0.003 0.031 16.88 8.0.28 0.007 0.036 16.63 8.0.27 0.017 0.028 16.61 8.0.26 0.010 0.034 16.75 8.0.25 0.017 0.026 16.61 8.0.24 0.013 0.032 16.63 8.0.23 0.007 0.038 16.75 8.0.22 0.011 0.036 16.59 8.0.21 0.009 0.035 16.63 8.0.20 0.014 0.032 16.75 8.0.19 0.006 0.038 16.87 8.0.18 0.015 0.033 16.63 8.0.17 0.007 0.037 16.71 8.0.16 0.015 0.029 16.60 8.0.15 0.019 0.025 16.61 8.0.14 0.016 0.025 16.75 8.0.13 0.015 0.027 16.75 8.0.12 0.014 0.028 16.63 8.0.11 0.004 0.038 16.63 8.0.10 0.012 0.031 16.52 8.0.9 0.017 0.026 16.75 8.0.8 0.011 0.032 16.63 8.0.7 0.013 0.029 16.75 8.0.6 0.014 0.031 16.52 8.0.5 0.013 0.030 16.63 8.0.3 0.008 0.035 16.52 8.0.2 0.014 0.029 16.85 8.0.1 0.011 0.031 16.74
preferences:dark mode live preview
56.32 ms | 403 KiB | 5 Q