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'] ); } } elseif ( is_admin() || ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) ) { $determined_locale = get_user_locale(); } if ( ! $determined_locale ) { $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.3.110.0060.02920.94
8.3.100.0060.02916.50
8.3.90.0060.05126.77
8.3.80.0030.05117.97
8.3.70.0200.06916.50
8.3.60.0160.06217.00
8.3.50.0130.05918.40
8.3.40.0100.05720.46
8.3.30.0100.05720.34
8.3.20.0060.06424.18
8.3.10.0070.04924.66
8.3.00.0130.04926.16
8.2.230.0000.03822.58
8.2.220.0030.03424.06
8.2.210.0070.03026.77
8.2.200.0030.04116.75
8.2.190.0070.06916.74
8.2.180.0100.07116.50
8.2.170.0100.06119.04
8.2.160.0070.06022.96
8.2.150.0040.03225.66
8.2.140.0060.03224.66
8.2.130.0040.03326.16
8.2.120.0070.03022.32
8.2.110.0100.04719.41
8.2.100.0140.05717.81
8.2.90.0030.05718.22
8.2.80.0000.05219.16
8.2.70.0030.05319.35
8.2.60.0100.05119.22
8.2.50.0030.05119.37
8.2.40.0000.05719.48
8.2.30.0070.05019.28
8.2.20.0060.04817.47
8.2.10.0030.05017.63
8.2.00.0100.04617.88
8.1.290.0030.04330.84
8.1.280.0030.06825.92
8.1.270.0030.04524.66
8.1.260.0000.03826.35
8.1.250.0130.04828.09
8.1.240.0070.04922.31
8.1.230.0070.04021.07
8.1.220.0000.05117.91
8.1.210.0060.04219.14
8.1.200.0070.04417.35
8.1.190.0030.04617.35
8.1.180.0030.05117.48
8.1.170.0030.04917.47
8.1.160.0000.05317.34
8.1.150.0000.05317.60
8.1.140.0000.05117.47
8.1.130.0130.04317.38
8.1.120.0070.04417.59
8.1.110.0060.04517.60
8.1.100.0100.04017.60
8.1.90.0030.04917.47
8.1.80.0000.05317.60
8.1.70.0070.04617.59
8.1.60.0070.04617.72
8.1.50.0030.04817.60
8.1.40.0030.05217.59
8.1.30.0100.04217.72
8.1.20.0070.04517.72
8.1.10.0000.05417.59
8.1.00.0030.04817.47
8.0.300.0060.04520.39
8.0.290.0070.05117.12
8.0.280.0100.05017.12
8.0.270.0070.05217.12
8.0.260.0030.05717.12
8.0.250.0100.04917.12
8.0.240.0000.05517.12
8.0.230.0030.05217.12
8.0.220.0030.05317.12
8.0.210.0030.05317.12
8.0.200.0070.05617.12
8.0.190.0030.05517.12
8.0.180.0000.06017.12
8.0.170.0070.05217.12
8.0.160.0070.05217.12
8.0.150.0030.05417.12
8.0.140.0030.05318.61
8.0.130.0000.05718.61
8.0.120.0070.04918.61
8.0.110.0030.05318.74
8.0.100.0000.05818.49
8.0.90.0030.05818.62
8.0.80.0070.05618.62
8.0.70.0000.06317.12
8.0.60.0070.05317.12
8.0.50.0070.05117.12
8.0.30.0060.05117.12
8.0.20.0100.05317.12
8.0.10.0000.06017.12

preferences:
28.41 ms | 403 KiB | 5 Q