3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* TESTING: http://programmers.stackexchange.com/questions/120378/is-error-suppression-acceptable-in-role-of-logic-mechanism/120386#120386 Elapsed Time[µseconds] Check, Exists : 50000 - Check, Exists : 94718 (user), 342 (system) EACH - Check, Exists : 1.89436E-6 (user), 6.84E-9 (system) Suppress, Exists : 50000 - Suppress, Exists : 146815 (user), 170 (system) EACH - Suppress, Exists : 2.9363E-6 (user), 3.4E-9 (system) Check, Missing : 50000 - Check, Missing : 84252 (user), 82 (system) EACH - Check, Missing : 1.68504E-6 (user), 1.64E-9 (system) Suppress, Missing: 50000 - Suppress, Missing: 200548 (user), 297 (system) EACH - Suppress, Missing: 4.01096E-6 (user), 5.94E-9 (system) Exists : 1.6 times slower (user), 0.5 (system) times slower. Missing: 2.4 times slower (user), 3.6 (system) times slower. */ define( 'TIMES', 50000 ); $results = array(); $messages = array( 'Check, Exists ', 'Suppress, Exists ', 'Check, Missing ', 'Suppress, Missing', ); $results[] = run_test( 'test_error_check', array('key'=>'foo','foo'=>'bar' ) ); $results[] = run_test( 'test_error_suppress', array('key'=>'foo','foo'=>'bar' ) ); $results[] = run_test( 'test_error_check', array('key'=>'foo' ) ); $results[] = run_test( 'test_error_suppress', array('key'=>'foo' ) ); $times = TIMES; $denominator = pow(10,6)*TIMES; echo "Elapsed Time[µseconds]"; foreach( $results as $index => $result ) { echo "\n{$messages[$index]}:"; echo "\n\t{$times} - {$messages[$index]}: {$result[0]} (user), {$result[1]} (system)"; $result[0] /= $denominator; $result[1] /= $denominator; echo "\n\tEACH - {$messages[$index]}: {$result[0]} (user), {$result[1]} (system)"; } echo "\n"; $messages = array( 'Exists ', 'Missing', ); for($i=0; $i<2; $i++) { $j = $i*2; $uratio = round($results[$j+1][0]/$results[$j][0],1); $sratio = round($results[$j+1][1]/$results[$j][1],1); echo "\n{$messages[$i]}: {$uratio} times slower (user), {$sratio} (system) times slower."; } echo "\n\n"; function test_error_suppress( $args, $key ) { return @$args[$key]; } function test_error_check( $args, $key ) { return ! empty( $args[$key] ) ? $args[$key] : false; } function run_test( $func_to_test, $args = array() ) { $dat = getrusage(); $utime_before = $dat["ru_utime.tv_sec"].$dat["ru_utime.tv_usec"]; $stime_before = $dat["ru_stime.tv_sec"].$dat["ru_stime.tv_usec"]; for( $i = 0; $i < TIMES; $i++ ) call_user_func( $func_to_test, $args, $args['key'] ); $dat = getrusage(); $utime_after = $dat["ru_utime.tv_sec"].$dat["ru_utime.tv_usec"]; $stime_after = $dat["ru_stime.tv_sec"].$dat["ru_stime.tv_usec"]; $utime_elapsed = ($utime_after - $utime_before); $stime_elapsed = ($stime_after - $stime_before); return array( $utime_elapsed, $stime_elapsed ); }

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.0.110.0030.03217.09
8.0.100.0080.02716.95
8.0.90.0000.03517.10
8.0.80.0160.03517.08
8.0.70.0000.03417.16
8.0.60.0060.03216.99
8.0.50.0040.03516.96
8.0.30.0090.04117.09
8.0.20.0090.04417.17
8.0.10.0000.03817.11
8.0.00.0130.05517.10
7.4.240.0000.03416.51
7.4.230.0050.04316.54
7.4.220.0210.07416.62
7.4.210.0060.06116.77
7.4.200.0040.03516.75
7.4.190.0000.03616.53
7.4.160.0130.03616.58
7.4.150.0100.04516.70
7.4.140.0070.07516.74
7.4.130.0150.05116.79
7.4.120.0130.03716.60
7.4.110.0160.05516.61
7.4.100.0060.04916.75
7.4.90.0070.04516.63
7.4.80.0130.04519.39
7.4.70.0100.04216.66
7.4.60.0140.03816.74
7.4.50.0000.02716.73
7.4.40.0020.04616.67
7.4.30.0180.07016.70
7.4.00.0110.03715.30
7.3.300.0030.02916.54
7.3.290.0080.04216.56
7.3.280.0110.05016.57
7.3.270.0070.04816.71
7.3.260.0100.04016.62
7.3.250.0100.06016.70
7.3.240.0130.03716.55
7.3.230.0070.05116.64
7.3.210.0170.06216.63
7.3.200.0100.07616.67
7.3.190.0110.05116.66
7.3.180.0030.04516.59
7.3.170.0140.03416.57
7.3.160.0100.04016.62
7.3.120.0080.03714.79
7.3.10.0070.03816.77
7.3.00.0000.04416.71
7.2.330.0090.04216.91
7.2.320.0120.04116.86
7.2.310.0090.05116.79
7.2.300.0100.04216.91
7.2.290.0070.04716.56
7.2.130.0000.04716.76
7.2.120.0030.04016.97
7.2.110.0050.04316.81
7.2.100.0000.04516.89
7.2.90.0000.04616.96
7.2.80.0030.04716.89
7.2.70.0020.04416.86
7.2.60.0030.03816.94
7.2.50.0080.03917.10
7.2.40.0150.03716.88
7.2.30.0070.03617.02
7.2.20.0140.03217.00
7.2.10.0100.03616.66
7.2.00.0050.04418.29
7.1.250.0130.05915.43
7.1.200.0030.03415.81
7.1.100.0470.06015.54
7.1.70.0000.03817.26
7.1.60.0100.07019.30
7.1.50.0160.05616.93
7.1.00.0000.06022.31
7.0.200.0040.03316.89
7.0.140.0070.11022.10
7.0.120.0030.11722.09
7.0.60.0030.12319.96
7.0.50.0070.07017.92
7.0.40.0070.07019.96
7.0.30.0230.06720.25
7.0.20.0270.09320.23
7.0.10.0070.10020.09
7.0.00.0200.11020.07
5.6.210.0070.20320.54
5.6.200.0130.20318.23
5.6.190.0100.18020.77
5.6.180.0600.17720.64
5.6.170.0300.18320.52
5.6.160.0070.20320.48
5.6.150.0100.19018.29
5.6.140.0200.19018.24
5.6.130.0000.14718.17
5.6.120.0030.19721.03
5.6.110.0030.14321.00
5.6.100.0100.20321.17
5.6.90.0100.21021.16
5.6.80.0070.19020.32
5.5.350.0230.18020.46
5.5.340.0070.16317.92
5.5.330.0030.20020.40
5.5.320.0330.18320.39
5.5.310.0130.15020.28
5.5.300.0070.20317.98
5.5.290.0000.20717.95
5.5.280.0030.15020.87
5.5.270.0070.16020.69
5.5.260.0070.19320.82
5.5.250.0030.14020.52
5.5.240.0070.19720.21
5.4.450.0070.18719.57
5.4.440.0070.16719.20
5.4.430.0070.20319.56
5.4.420.0030.20319.51
5.4.410.0100.18719.42
5.4.400.0070.19019.16
5.4.390.0130.17318.87
5.4.380.0100.13019.02
5.4.370.0070.14718.92
5.4.360.0100.20018.85
5.4.350.0130.19719.14
5.4.340.0100.21318.85
5.4.320.0100.14719.18
5.4.310.0030.14319.24
5.4.300.0030.20719.20
5.4.290.0030.15019.04
5.4.280.0030.20018.85
5.4.270.0070.15718.87
5.4.260.0170.17019.20
5.4.250.0070.20019.19
5.4.240.0030.18319.14
5.4.230.0170.20319.13
5.4.220.0070.14018.88
5.4.210.0070.19019.14
5.4.200.0030.18019.23
5.4.190.0070.13719.14
5.4.180.0030.16319.17
5.4.170.0070.21019.23
5.4.160.0070.19719.22
5.4.150.0030.18018.85
5.4.140.0030.14016.42
5.4.130.0000.14016.39
5.4.120.0030.13316.37
5.4.110.0070.13316.54
5.4.100.0070.13316.55
5.4.90.0070.13016.35
5.4.80.0070.13016.34
5.4.70.0030.13316.40
5.4.60.0070.13016.38
5.4.50.0070.13716.52
5.4.40.0030.13316.38
5.4.30.0000.13716.52
5.4.20.0000.15316.45
5.4.10.0070.13016.34
5.4.00.0000.20315.81
5.3.290.0000.17014.70
5.3.280.0030.16714.63
5.3.270.0100.19314.64
5.3.260.0130.21714.69
5.3.250.0070.21014.65
5.3.240.0100.16714.64
5.3.230.0070.16014.72
5.3.220.0030.16014.60
5.3.210.0070.15714.75
5.3.200.0000.16014.69
5.3.190.0030.16314.71
5.3.180.0030.16314.68
5.3.170.0100.15714.75
5.3.160.0000.19714.59
5.3.150.0070.15714.63
5.3.140.0030.17014.73
5.3.130.0000.17714.57
5.3.120.0030.16014.58
5.3.110.0070.16314.58
5.3.100.0000.22014.19
5.3.90.0030.21314.16
5.3.80.0030.17314.06
5.3.70.0070.16013.94
5.3.60.0000.18014.11
5.3.50.0000.17314.00
5.3.40.0030.22313.93
5.3.30.0000.22313.91
5.3.20.0070.19013.76
5.3.10.0130.22313.66
5.3.00.0100.23013.82
5.2.170.0030.17711.19
5.2.160.0070.19011.17
5.2.150.0070.21711.26
5.2.140.0070.22311.33
5.2.130.0000.16711.24
5.2.120.0030.19711.13
5.2.110.0070.19011.19
5.2.100.0030.23311.21
5.2.90.0030.22011.14
5.2.80.0030.18711.09
5.2.70.0100.16011.24
5.2.60.0070.22711.08
5.2.50.0030.20310.98
5.2.40.0100.21711.21
5.2.30.0070.17011.11
5.2.20.0070.16711.00
5.2.10.0030.22310.98
5.2.00.0000.21310.98
5.1.60.0000.16010.98
5.1.50.0000.22310.98
5.1.40.0100.21310.98
5.1.30.0000.22310.98
5.1.20.0000.22710.98
5.1.10.0100.21310.98
5.1.00.0030.20010.98
5.0.50.0070.27710.98
5.0.40.0030.21310.98
5.0.30.0070.26010.98
5.0.20.0070.19710.98
5.0.10.0070.26710.98
5.0.00.0030.26010.98
4.4.90.0100.25010.98
4.4.80.0030.19710.98
4.4.70.0000.25010.98
4.4.60.0000.20310.98
4.4.50.0030.24310.98
4.4.40.0000.25010.98
4.4.30.0130.25010.98
4.4.20.0030.23310.98
4.4.10.0000.27310.98
4.4.00.0030.27310.98
4.3.110.0030.21010.98
4.3.100.0100.26010.98
4.3.90.0070.25710.98
4.3.80.0000.32010.98
4.3.70.0030.20710.98
4.3.60.0030.20710.98
4.3.50.0030.24310.98
4.3.40.0000.24010.98
4.3.30.0000.23310.98
4.3.20.0030.21010.98
4.3.10.0070.25710.98
4.3.00.0030.19710.98

preferences:
39.67 ms | 401 KiB | 5 Q