3v4l.org

run code in 300+ PHP versions simultaneously
<?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_locale_name( $a ) { return $a; } 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 ) );
Output for 8.3.7
current: 0.022599063s proposed: 0.013773076s Proposed is 1.64x faster
Output for 8.3.6
current: 0.015334429s proposed: 0.012355251s Proposed is 1.24x faster
Output for 8.3.5
current: 0.023185958s proposed: 0.013921333s Proposed is 1.67x faster
Output for 8.3.4
current: 0.02135743s proposed: 0.015415083s Proposed is 1.39x faster
Output for 8.3.3
current: 0.01622444s proposed: 0.012647487s Proposed is 1.28x faster
Output for 8.3.2
current: 0.008472875s proposed: 0.006713539s Proposed is 1.26x faster
Output for 8.3.1
current: 0.008327626s proposed: 0.006506501s Proposed is 1.28x faster
Output for 8.3.0
current: 0.008630729s proposed: 0.006860202s Proposed is 1.26x faster
Output for 8.2.19
current: 0.017914247s proposed: 0.013069456s Proposed is 1.37x faster
Output for 8.2.18
current: 0.019681492s proposed: 0.014809871s Proposed is 1.33x faster
Output for 8.2.17
current: 0.015654581s proposed: 0.012780744s Proposed is 1.22x faster
Output for 8.2.16
current: 0.020048293s proposed: 0.018710019s Proposed is 1.07x faster
Output for 8.2.15
current: 0.00804515s proposed: 0.006895771s Proposed is 1.17x faster
Output for 8.2.14
current: 0.008044819s proposed: 0.006978262s Proposed is 1.15x faster
Output for 8.2.13
current: 0.00820279s proposed: 0.006504503s Proposed is 1.26x faster
Output for 8.2.12
current: 0.007955895s proposed: 0.006680825s Proposed is 1.19x faster
Output for 8.2.11
current: 0.015464036s proposed: 0.010687711s Proposed is 1.45x faster
Output for 8.2.10
current: 0.011984297s proposed: 0.008459625s Proposed is 1.42x faster
Output for 8.2.9
current: 0.011333054s proposed: 0.00817903s Proposed is 1.39x faster
Output for 8.2.8
current: 0.013429164s proposed: 0.011842242s Proposed is 1.13x faster
Output for 8.2.7
current: 0.011718327s proposed: 0.008173569s Proposed is 1.43x faster
Output for 8.2.6
current: 0.012022051s proposed: 0.008287144s Proposed is 1.45x faster
Output for 8.2.5
current: 0.011429665s proposed: 0.008110351s Proposed is 1.41x faster
Output for 8.2.4
current: 0.011734178s proposed: 0.008584355s Proposed is 1.37x faster
Output for 8.2.3
current: 0.011493795s proposed: 0.008521977s Proposed is 1.35x faster
Output for 8.2.2
current: 0.011830751s proposed: 0.00850274s Proposed is 1.39x faster
Output for 8.2.1
current: 0.011626055s proposed: 0.008505886s Proposed is 1.37x faster
Output for 8.2.0
current: 0.011091357s proposed: 0.008433881s Proposed is 1.32x faster
Output for 8.1.28
current: 0.015048556s proposed: 0.011748853s Proposed is 1.28x faster
Output for 8.1.27
current: 0.008265495s proposed: 0.006706488s Proposed is 1.23x faster
Output for 8.1.26
current: 0.008483524s proposed: 0.006786481s Proposed is 1.25x faster
Output for 8.1.25
current: 0.008153213s proposed: 0.006696099s Proposed is 1.22x faster
Output for 8.1.24
current: 0.016069478s proposed: 0.010963591s Proposed is 1.47x faster
Output for 8.1.23
current: 0.009690824s proposed: 0.007158468s Proposed is 1.35x faster
Output for 8.1.22
current: 0.01107782s proposed: 0.007777332s Proposed is 1.42x faster
Output for 8.1.21
current: 0.010838674s proposed: 0.007781422s Proposed is 1.39x faster
Output for 8.1.20
current: 0.01077524s proposed: 0.007824091s Proposed is 1.38x faster
Output for 8.1.19
current: 0.011713711s proposed: 0.007639604s Proposed is 1.53x faster
Output for 8.1.18
current: 0.013239755s proposed: 0.0077755s Proposed is 1.70x faster
Output for 8.1.17
current: 0.011964732s proposed: 0.00797704s Proposed is 1.50x faster
Output for 8.1.16
current: 0.0107526s proposed: 0.007815796s Proposed is 1.38x faster
Output for 8.1.15
current: 0.010835044s proposed: 0.007926115s Proposed is 1.37x faster
Output for 8.1.14
current: 0.011109322s proposed: 0.008108997s Proposed is 1.37x faster
Output for 8.1.13
current: 0.011066521s proposed: 0.008299947s Proposed is 1.33x faster
Output for 8.1.12
current: 0.010881332s proposed: 0.007968133s Proposed is 1.37x faster
Output for 8.1.11
current: 0.010813504s proposed: 0.007834231s Proposed is 1.38x faster
Output for 8.1.10
current: 0.011450153s proposed: 0.007973263s Proposed is 1.44x faster
Output for 8.1.9
current: 0.010776595s proposed: 0.008448638s Proposed is 1.28x faster
Output for 8.1.8
current: 0.010757518s proposed: 0.008267848s Proposed is 1.30x faster
Output for 8.1.7
current: 0.010665425s proposed: 0.008108157s Proposed is 1.32x faster
Output for 8.1.6
current: 0.011037576s proposed: 0.007521021s Proposed is 1.47x faster
Output for 8.1.5
current: 0.010691894s proposed: 0.00790842s Proposed is 1.35x faster
Output for 8.1.4
current: 0.010981169s proposed: 0.007887541s Proposed is 1.39x faster
Output for 8.1.3
current: 0.013456042s proposed: 0.007933478s Proposed is 1.70x faster
Output for 8.1.2
current: 0.011077983s proposed: 0.008208206s Proposed is 1.35x faster
Output for 8.1.1
current: 0.011459731s proposed: 0.00868836s Proposed is 1.32x faster
Output for 8.1.0
current: 0.011476093s proposed: 0.00809961s Proposed is 1.42x faster
Output for 8.0.30
current: 0.011764574s proposed: 0.009375774s Proposed is 1.25x faster
Output for 8.0.29
current: 0.012085367s proposed: 0.009807116s Proposed is 1.23x faster
Output for 8.0.28
current: 0.012778095s proposed: 0.009584639s Proposed is 1.33x faster
Output for 8.0.27
current: 0.013577151s proposed: 0.009641786s Proposed is 1.41x faster
Output for 8.0.26
current: 0.012062256s proposed: 0.009606149s Proposed is 1.26x faster
Output for 8.0.25
current: 0.012145183s proposed: 0.009597022s Proposed is 1.27x faster
Output for 8.0.24
current: 0.013497501s proposed: 0.009281397s Proposed is 1.45x faster
Output for 8.0.23
current: 0.012842636s proposed: 0.00956954s Proposed is 1.34x faster
Output for 8.0.22
current: 0.01272781s proposed: 0.009741144s Proposed is 1.31x faster
Output for 8.0.21
current: 0.012367071s proposed: 0.009612952s Proposed is 1.29x faster
Output for 8.0.20
current: 0.01327427s proposed: 0.010102215s Proposed is 1.31x faster
Output for 8.0.19
current: 0.013738565s proposed: 0.010140325s Proposed is 1.35x faster
Output for 8.0.18
current: 0.012401837s proposed: 0.009992507s Proposed is 1.24x faster
Output for 8.0.17
current: 0.012592866s proposed: 0.0094732s Proposed is 1.33x faster
Output for 8.0.16
current: 0.012304783s proposed: 0.009880136s Proposed is 1.25x faster
Output for 8.0.15
current: 0.011756591s proposed: 0.009687352s Proposed is 1.21x faster
Output for 8.0.14
current: 0.012200858s proposed: 0.008701284s Proposed is 1.40x faster
Output for 8.0.13
current: 0.012081542s proposed: 0.008881484s Proposed is 1.36x faster
Output for 8.0.12
current: 0.012367211s proposed: 0.008911189s Proposed is 1.39x faster
Output for 8.0.11
current: 0.012043422s proposed: 0.009186058s Proposed is 1.31x faster
Output for 8.0.10
current: 0.012797833s proposed: 0.009554392s Proposed is 1.34x faster
Output for 8.0.9
current: 0.012682495s proposed: 0.009109013s Proposed is 1.39x faster
Output for 8.0.8
current: 0.01179856s proposed: 0.009713341s Proposed is 1.21x faster
Output for 8.0.7
current: 0.012401716s proposed: 0.009198661s Proposed is 1.35x faster
Output for 8.0.6
current: 0.011502933s proposed: 0.009337413s Proposed is 1.23x faster
Output for 8.0.5
current: 0.011560471s proposed: 0.009331623s Proposed is 1.24x faster
Output for 8.0.3
current: 0.011407804s proposed: 0.00907045s Proposed is 1.26x faster
Output for 8.0.2
current: 0.013505105s proposed: 0.009622581s Proposed is 1.40x faster
Output for 8.0.1
current: 0.012188745s proposed: 0.009566976s Proposed is 1.27x faster

preferences:
98.03 ms | 401 KiB | 91 Q