3v4l.org

run code in 300+ PHP versions simultaneously
<?php define( 'WP_ADMIN', true ); // Most likely front-end scenario. function is_admin() { if ( isset( $GLOBALS['current_screen'] ) ) { return $GLOBALS['current_screen']->in_admin(); } elseif ( defined( 'WP_ADMIN' ) ) { return WP_ADMIN; } return false; } function wp_is_json_request() { if ( isset( $_SERVER['HTTP_ACCEPT'] ) && wp_is_json_media_type( $_SERVER['HTTP_ACCEPT'] ) ) { return true; } if ( isset( $_SERVER['CONTENT_TYPE'] ) && wp_is_json_media_type( $_SERVER['CONTENT_TYPE'] ) ) { return true; } return false; } function is_multisite() { if ( defined( 'MULTISITE' ) ) { return MULTISITE; } if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) { return true; } return false; } function get_option( $what ) { switch ( $what ) : case 'WPLANG': return 'en_US'; endswitch; return false; } function get_locale() { global $locale, $wp_local_package; if ( isset( $locale ) ) { /** This filter is documented in wp-includes/l10n.php */ return apply_filters( 'locale', $locale ); } if ( isset( $wp_local_package ) ) { $locale = $wp_local_package; } // WPLANG was defined in wp-config. if ( defined( 'WPLANG' ) ) { $locale = WPLANG; } // If multisite, check options. if ( is_multisite() ) { // Don't check blog option when installing. if ( wp_installing() ) { $ms_locale = get_site_option( 'WPLANG' ); } else { $ms_locale = get_option( 'WPLANG' ); if ( false === $ms_locale ) { $ms_locale = get_site_option( 'WPLANG' ); } } if ( false !== $ms_locale ) { $locale = $ms_locale; } } else { $db_locale = get_option( 'WPLANG' ); if ( false !== $db_locale ) { $locale = $db_locale; } } if ( empty( $locale ) ) { $locale = 'en_US'; } /** * Filters the locale ID of the WordPress installation. * * @since 1.5.0 * * @param string $locale The locale ID. */ return apply_filters( 'locale', $locale ); } function get_user_locale( $user = 0 ) { $user_object = false; if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) { $user_object = wp_get_current_user(); } elseif ( $user instanceof WP_User ) { $user_object = $user; } elseif ( $user && is_numeric( $user ) ) { $user_object = get_user_by( 'id', $user ); } if ( ! $user_object ) { return get_locale(); } $locale = $user_object->locale; return $locale ? $locale : get_locale(); } function apply_filters( $a, $b ) { return $b; } function sanitize_locale_name( $a ) { // Limit to A-Z, a-z, 0-9, '_', '-'. $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $locale_name ); /** * Filters a sanitized locale name string. * * @since 6.2.1 * * @param string $sanitized The sanitized locale name. * @param string $locale_name The locale name before sanitization. */ return apply_filters( 'sanitize_locale_name', $sanitized, $locale_name ); } function determine_locale_actual() { /** * 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'] && ( ! empty( $_GET['wp_lang'] ) || ! empty( $_COOKIE['wp_lang'] ) ) ) { if ( ! empty( $_GET['wp_lang'] ) ) { $determined_locale = sanitize_locale_name( $_GET['wp_lang'] ); } else { $determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] ); } } else if ( ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) || is_admin() ) { $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 ); } 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 ); } determine_locale_actual(); determine_locale_proposed(); $its = 1e5; $t = hrtime(true); for ( $i = 0; $i++ < $its; ) determine_locale_actual(); echo 'current: ', $old = ( hrtime(true)-$t ) / 1e9, "s\n"; $t = hrtime(true); for ( $i = 0; $i++ < $its; ) determine_locale_proposed(); echo 'proposed: ', $new = ( hrtime(true)-$t ) / 1e9, "s\n\n"; printf( 'Proposed is %sx faster', number_format( $old / $new, 2 ) );

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).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.20.0000.03817.99
8.4.10.0070.07424.05
8.3.140.0100.07816.56
8.3.130.0090.02816.68
8.3.120.0100.03219.09
8.3.110.0100.05020.94
8.3.100.0070.03324.06
8.3.90.0030.03326.77
8.3.80.0030.04418.30
8.3.70.0130.05618.55
8.3.60.0070.06416.88
8.3.50.0130.06718.34
8.3.40.0100.06020.46
8.3.30.0130.05520.30
8.3.20.0070.03024.18
8.3.10.0030.03324.66
8.3.00.0160.04126.16
8.2.260.0160.05616.71
8.2.250.0030.03418.51
8.2.240.0070.03119.10
8.2.230.0070.07022.58
8.2.220.0000.04137.54
8.2.210.0000.03726.77
8.2.200.0070.05216.25
8.2.190.0130.06516.70
8.2.180.0100.06316.63
8.2.170.0030.06518.88
8.2.160.0070.06022.96
8.2.150.0070.03025.66
8.2.140.0060.03124.66
8.2.130.0170.05326.16
8.2.120.0070.03122.26
8.2.110.0100.05119.39
8.2.100.0070.06618.03
8.2.90.0070.05018.41
8.2.80.0090.05719.41
8.2.70.0100.04617.63
8.2.60.0030.05217.75
8.2.50.0070.04917.75
8.2.40.0030.05117.75
8.2.30.0060.04917.75
8.2.20.0030.05117.63
8.2.10.0100.04717.75
8.2.00.0070.05217.63
8.1.310.0130.06518.63
8.1.300.0040.03518.34
8.1.290.0000.06618.88
8.1.280.0070.06425.92
8.1.270.0100.05224.66
8.1.260.0100.05026.35
8.1.250.0000.03728.09
8.1.240.0030.05822.44
8.1.230.0070.05420.97
8.1.220.0070.05017.91
8.1.210.0000.05119.10
8.1.200.0000.05217.47
8.1.190.0060.04617.35
8.1.180.0000.05517.35
8.1.170.0030.05117.35
8.1.160.0030.05217.35
8.1.150.0070.04917.59
8.1.140.0070.04717.47
8.1.130.0000.05417.60
8.1.120.0070.04717.60
8.1.110.0000.05317.73
8.1.100.0060.04517.60
8.1.90.0000.05317.60
8.1.80.0030.05117.60
8.1.70.0060.04817.47
8.1.60.0100.04217.60
8.1.50.0030.05017.72
8.1.40.0030.05117.50
8.1.30.0000.05317.72
8.1.20.0030.05217.73
8.1.10.0030.05217.60
8.1.00.0030.05317.47
8.0.300.0000.05320.21
8.0.290.0070.05217.12
8.0.280.0000.06017.12
8.0.270.0070.05217.12
8.0.260.0030.05717.12
8.0.250.0060.05417.12
8.0.240.0000.05717.12
8.0.230.0030.05317.12
8.0.220.0100.04817.12
8.0.210.0000.05717.12
8.0.200.0030.05617.12
8.0.190.0070.05317.12
8.0.180.0030.05817.12
8.0.170.0030.05717.13
8.0.160.0030.06017.12
8.0.150.0030.06117.12
8.0.140.0000.05817.12
8.0.130.0060.05517.12
8.0.120.0000.05817.12
8.0.110.0030.05717.12
8.0.100.0100.06017.12
8.0.90.0030.06017.12
8.0.80.0000.06017.12
8.0.70.0030.05917.12
8.0.60.0070.05317.12
8.0.50.0070.05917.12
8.0.30.0030.06817.12
8.0.20.0030.06417.12
8.0.10.0130.05117.12

preferences:
22.45 ms | 403 KiB | 5 Q