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.4.20.0030.02817.80
8.4.10.0000.03123.90
8.3.150.0070.02318.93
8.3.140.0140.04920.80
8.3.130.0000.03018.31
8.3.120.0070.02420.57
8.3.110.0070.04920.94
8.3.100.0090.02224.06
8.3.90.0100.01926.77
8.3.80.0070.03018.43
8.3.70.0070.05116.63
8.3.60.0130.05316.88
8.3.50.0130.05416.84
8.3.40.0140.06420.48
8.3.30.0100.04520.17
8.3.20.0060.02524.18
8.3.10.0130.03324.66
8.3.00.0130.04226.16
8.2.270.0060.02217.09
8.2.260.0070.04318.61
8.2.250.0070.02218.29
8.2.240.0100.06017.15
8.2.230.0060.02522.58
8.2.220.0030.02937.54
8.2.210.0100.04426.77
8.2.200.0060.03118.54
8.2.190.0070.04816.70
8.2.180.0130.04916.50
8.2.170.0030.05319.27
8.2.160.0130.04222.96
8.2.150.0000.03025.66
8.2.140.0100.05124.66
8.2.130.0000.03026.16
8.2.120.0040.03622.24
8.2.110.0100.04519.51
8.2.100.0100.04217.84
8.2.90.0030.03719.86
8.2.80.0100.03419.36
8.2.70.0040.03917.63
8.2.60.0120.03117.75
8.2.50.0030.04017.63
8.2.40.0000.04117.63
8.2.30.0100.03217.88
8.2.20.0030.03917.75
8.2.10.0040.03917.63
8.2.00.0030.03817.88
8.1.310.0100.05516.89
8.1.300.0070.04717.85
8.1.290.0070.03218.88
8.1.280.0200.06525.92
8.1.270.0100.02322.22
8.1.260.0030.02926.35
8.1.250.0030.02828.09
8.1.240.0000.05022.25
8.1.230.0070.03121.09
8.1.220.0040.03517.74
8.1.210.0000.03619.04
8.1.200.0000.03917.35
8.1.190.0060.03817.47
8.1.180.0030.03817.47
8.1.170.0030.03717.47
8.1.160.0000.04217.60
8.1.150.0030.03517.60
8.1.140.0030.03617.38
8.1.130.0070.03317.59
8.1.120.0070.03217.60
8.1.110.0060.03417.47
8.1.100.0070.03417.60
8.1.90.0030.03717.47
8.1.80.0000.03917.60
8.1.70.0040.03517.47
8.1.60.0070.03317.72
8.1.50.0000.04017.48
8.1.40.0100.03017.72
8.1.30.0030.03617.60
8.1.20.0030.03717.72
8.1.10.0030.03717.50
8.1.00.0060.03417.60
8.0.300.0030.03720.18
8.0.290.0070.03717.12
8.0.280.0000.04617.12
8.0.270.0030.04217.12
8.0.260.0030.04217.12
8.0.250.0100.03617.12
8.0.240.0070.03917.12
8.0.230.0000.04517.12
8.0.220.0030.04117.12
8.0.210.0030.04017.12
8.0.200.0100.03617.12
8.0.190.0100.03617.12
8.0.180.0070.04017.12
8.0.170.0040.04317.12
8.0.160.0000.04517.12
8.0.150.0030.04317.12
8.0.140.0100.03317.12
8.0.130.0060.03917.12
8.0.120.0030.03917.12
8.0.110.0000.04417.12
8.0.100.0030.04117.12
8.0.90.0030.04017.12
8.0.80.0070.03717.12
8.0.70.0030.04217.12
8.0.60.0030.04117.12
8.0.50.0100.03517.12
8.0.30.0000.04317.12
8.0.20.0060.03817.12
8.0.10.0070.03617.12

preferences:
28.53 ms | 403 KiB | 5 Q