3v4l.org

run code in 300+ PHP versions simultaneously
<?php // $this->last_result analogue in WPDB for 80000 posts' "SELECT meta_key, meta_value WHERE...." $last_result = array_fill( 0, 80000, (object) [ 'meta_key' => 'hello_who', 'meta_value' => str_repeat( 'World and WordPress ', 20 ), ] ); const ARRAY_N = 0b0; $output = 0b0; // Startup engines; number_format( hrtime( true ) / 1e9 ); $new_array = []; foreach ( (array) $last_result as $row ) { // ...integer-keyed row arrays. $new_array[] = array_values( get_object_vars( $row ) ); } $new_array = []; foreach ( (array) $last_result as $row ) { // ...column name-keyed row arrays. $new_array[] = get_object_vars( $row ); } $new_array = []; // Test. $new_array = []; $t = hrtime( true ); foreach ( (array) $last_result as $row ) { if ( ARRAY_N === $output ) { // ...integer-keyed row arrays. $new_array[] = array_values( get_object_vars( $row ) ); } else { // ...column name-keyed row arrays. $new_array[] = get_object_vars( $row ); } } echo 'Old ARRAY_N: ', number_format( ( hrtime( true ) - $t ) / 1e9, 5 ).'s', "\n"; $new_array = []; $t = hrtime( true ); if ( ARRAY_N === $output ) { foreach ( (array) $last_result as $row ) { // ...integer-keyed row arrays. $new_array[] = array_values( get_object_vars( $row ) ); } } else { foreach ( (array) $last_result as $row ) { // ...column name-keyed row arrays. $new_array[] = get_object_vars( $row ); } } echo 'New ARRAY_N: ', number_format( ( hrtime( true ) - $t ) / 1e9, 5 ).'s', "\n"; // Test ARRAY_A now. $output = 0b1; $new_array = []; $t = hrtime( true ); foreach ( (array) $last_result as $row ) { if ( ARRAY_N === $output ) { // ...integer-keyed row arrays. $new_array[] = array_values( get_object_vars( $row ) ); } else { // ...column name-keyed row arrays. $new_array[] = get_object_vars( $row ); } } echo 'Old ARRAY_A: ', number_format( ( hrtime( true ) - $t ) / 1e9, 5 ).'s', "\n"; $new_array = []; $t = hrtime( true ); if ( ARRAY_N === $output ) { foreach ( (array) $last_result as $row ) { // ...integer-keyed row arrays. $new_array[] = array_values( get_object_vars( $row ) ); } } else { foreach ( (array) $last_result as $row ) { // ...column name-keyed row arrays. $new_array[] = get_object_vars( $row ); } } echo 'New ARRAY_A: ', number_format( ( hrtime( true ) - $t ) / 1e9, 5 ).'s', "\n";

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.0400.04039.14
8.4.10.0370.05742.44
8.3.150.0290.03637.14
8.3.140.0250.02237.28
8.3.130.0200.02338.23
8.3.120.0380.03439.40
8.3.110.0330.03339.02
8.3.100.0370.03039.29
8.3.90.0200.02741.31
8.3.80.0240.03136.94
8.3.70.0370.04437.01
8.3.60.0400.05338.20
8.3.50.0430.04040.87
8.3.40.0400.04740.80
8.3.30.0430.04339.37
8.3.20.0290.01642.50
8.3.10.0190.02642.52
8.3.00.0110.01845.45
8.2.260.0230.04637.65
8.2.250.0370.03737.70
8.2.240.0230.03937.54
8.2.230.0270.02737.27
8.2.220.0230.04637.54
8.2.210.0100.03538.85
8.2.200.0250.01938.14
8.2.190.0390.04936.89
8.2.180.0360.05336.93
8.2.170.0370.04339.47
8.2.160.0190.03544.48
8.2.150.0200.02441.26
8.2.140.0270.01739.88
8.2.130.0160.02940.97
8.2.120.0130.03041.18
8.2.110.0030.04944.30
8.2.100.0420.04238.47
8.2.90.0130.03839.91
8.2.80.0140.03838.68
8.2.70.0100.04438.28
8.2.60.0130.03938.72
8.2.50.0100.04238.24
8.2.40.0220.02538.81
8.2.30.0100.03938.65
8.2.20.0210.03139.65
8.2.10.0260.03838.64
8.2.00.0170.03439.89
8.1.310.0500.03652.32
8.1.300.0370.02751.55
8.1.290.0270.04453.63
8.1.280.0730.06053.62
8.1.270.0160.01349.98
8.1.260.0230.00350.09
8.1.250.0180.00750.00
8.1.240.0290.00348.64
8.1.230.0290.01345.83
8.1.220.0130.00945.75
8.1.210.0130.01045.23
8.1.200.0130.02045.25
8.1.190.0070.01845.10
8.1.180.0180.00745.10
8.1.170.0160.00646.54
8.1.160.0230.00746.78
8.1.150.0230.00346.46
8.1.140.0240.00445.36
8.1.130.0180.00645.30
8.1.120.0240.00745.50
8.1.110.0090.01245.38
8.1.100.0270.00445.31
8.1.90.0300.00045.26
8.1.80.0270.00345.17
8.1.70.0150.01545.34
8.1.60.0190.01345.57
8.1.50.0210.01245.50
8.1.40.0280.00345.53
8.1.30.0290.00445.62
8.1.20.0210.01145.59
8.1.10.0280.04651.65
8.1.00.0300.04351.71
8.0.300.0270.04052.18
8.0.290.0260.05050.96
8.0.280.0310.05452.86
8.0.270.0140.05452.04
8.0.260.0170.06050.77
8.0.250.0200.04350.96
8.0.240.0240.03850.89
8.0.230.0270.04450.99
8.0.220.0360.03650.80
8.0.210.0340.03750.96
8.0.200.0380.03250.85
8.0.190.0310.04250.77
8.0.180.0310.04450.86
8.0.170.0260.04950.95
8.0.160.0310.04150.95
8.0.150.0380.03450.97
8.0.140.0230.04950.91
8.0.130.0380.03850.84
8.0.120.0140.05750.73
8.0.110.0290.04150.86
8.0.100.0170.05650.85
8.0.90.0260.04850.74
8.0.80.0300.03650.80
8.0.70.0290.04350.86
8.0.60.0240.04550.79
8.0.50.0230.05050.88
8.0.30.0340.04750.86
8.0.20.0350.03250.97
8.0.10.0300.03750.97
7.4.330.0200.04649.18
7.4.320.0200.05150.48
7.4.300.0100.05350.47
7.4.290.0290.03950.39
7.4.280.0260.04150.50
7.4.270.0140.05350.51
7.4.260.0220.04550.43
7.4.250.0160.04950.48
7.4.240.0170.04850.43
7.4.230.0210.05350.48
7.4.220.0280.03850.40
7.4.210.0270.04150.60
7.4.200.0230.04350.47
7.4.190.0130.05450.43
7.4.180.0260.04650.61
7.4.160.0270.04850.62
7.4.150.0140.05950.48
7.4.140.0190.05950.35
7.4.130.0210.05650.38
7.4.120.0190.06250.44
7.4.110.0250.05350.44
7.4.100.0230.05750.50
7.4.90.0170.06150.40
7.4.80.0200.06150.54
7.4.70.0300.04750.34
7.4.60.0200.06050.39
7.4.50.0160.05950.44
7.4.40.0240.05150.45
7.4.30.0190.06250.51
7.4.20.0300.05050.40
7.4.10.0230.05750.51
7.4.00.0240.05850.50

preferences:
69.73 ms | 403 KiB | 5 Q