3v4l.org

run code in 300+ PHP versions simultaneously
<?php function starts_with_strpos($haystack, $needle) { return strpos($haystack, $needle) === 0; } function starts_with_substr($haystack, $needle) { return substr($haystack, 0, strlen($needle)) === $needle; } // setup the haystack and needle $haystack = "Hello PHP"; $needle = "Hello"; // initialize the results array $results = array('substr' => array(), 'strpos' => array()); // Run the substr benchmark // exhaust the gc's threshhold at 10K $it = 10000; for($i = 0; $i < $it; $i++) { $t = microtime(true); starts_with_substr($haystack, $needle); $results['substr'][] = microtime(true) - $t; } // discard the first and last results as opline biased array_pop($results['substr']); array_shift($results['substr']); // Run the strpos benchmark for($i = 0; $i < $it; $i++) { $t = microtime(true); starts_with_strpos($haystack, $needle); $results['strpos'][] = microtime(true) - $t; } // discard the first and last results as opline biased array_pop($results['strpos']); array_shift($results['strpos']); // compare the results $a = array_sum($results['substr']) / $it; $b = array_sum($results['strpos']) / $it; printf("substr: %.6fs/iteration @ %d iterations\nstrpos: %.6fs/iteration @ %d iterations\n\n", $a, $it, $b, $it); // determine which is faster (substr or strpos) if ($a > $b) { // substr is slower printf("strpos is %d%% faster than substr\n", $b / $a * 100); } elseif ($b > $a) { // strpos is slower printf("substr is %d%% faster than strpos\n", $a / $b * 100); } else { // they're the same printf("strpos and substr are the same\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)
7.4.00.0100.01415.59
7.3.120.0070.01815.38
7.3.110.0050.02015.43
7.3.100.0000.02215.39
7.3.90.0070.01015.48
7.3.80.0080.01415.52
7.3.70.0070.01515.57
7.3.60.0060.01615.43
7.3.50.0110.01015.49
7.3.40.0070.01615.42
7.3.30.0050.01715.63
7.3.20.0080.01216.82
7.3.10.0090.01116.71
7.3.00.0080.00916.54
7.2.250.0050.02215.51
7.2.240.0040.02515.70
7.2.230.0060.02115.66
7.2.220.0050.01415.83
7.2.210.0080.01315.80
7.2.200.0080.01715.71
7.2.190.0080.01615.82
7.2.180.0070.01715.64
7.2.170.0050.01315.67
7.2.160.0070.02015.83
7.2.150.0030.01916.95
7.2.140.0040.01816.91
7.2.130.0030.01817.11
7.2.120.0070.01817.10
7.2.110.0100.01617.00
7.2.100.0070.01816.80
7.2.90.0030.02116.99
7.2.80.0070.01716.88
7.2.70.0130.01017.04
7.2.60.0060.01617.01
7.2.50.0030.02316.98
7.2.40.0070.01517.09
7.2.30.0060.01617.04
7.2.20.0040.02216.70
7.2.10.0030.02116.98
7.2.00.0070.01418.19
7.1.330.0100.01515.80
7.1.320.0060.01815.95
7.1.310.0060.01815.85
7.1.300.0020.02315.85
7.1.290.0050.01715.87
7.1.280.0030.02215.61
7.1.270.0050.02215.73
7.1.260.0050.01915.86
7.1.250.0100.01616.00
7.1.70.0030.01017.19
7.1.60.0130.02319.70
7.1.50.0030.02016.86
7.1.00.0030.08722.32
7.0.200.0190.01116.60
7.0.140.0070.07722.11
7.0.100.0130.05720.60
7.0.90.0270.08720.53
7.0.80.0270.08720.52
7.0.70.0200.08720.49
7.0.60.0070.08320.60
7.0.50.0300.08020.96
7.0.40.0130.07020.03
7.0.30.0070.08720.00
7.0.20.0170.07720.04
7.0.10.0070.09019.99
7.0.00.0100.08720.09
5.6.280.0030.09723.66
5.6.250.0100.11023.50
5.6.240.0000.09023.43
5.6.230.0200.07023.48
5.6.220.0130.09323.32
5.6.210.0100.09023.45
5.6.200.0100.09723.95
5.6.190.0030.10723.95
5.6.180.0100.07323.88
5.6.170.0130.09023.78
5.6.160.0030.06023.88
5.6.150.0030.07023.90
5.6.140.0170.10323.94
5.6.130.0000.09023.80
5.6.120.0100.10023.86
5.6.110.0130.09323.97
5.6.100.0030.09323.89
5.6.90.0100.09723.86
5.6.80.0070.09323.34
5.6.70.0070.05023.18
5.6.60.0030.05323.27
5.6.50.0100.04723.28
5.6.40.0000.05723.21
5.6.30.0030.05323.22
5.6.20.0130.04323.27
5.6.10.0100.08023.14
5.6.00.0100.05023.29
5.5.380.0130.09023.25
5.5.370.0070.10723.24
5.5.360.0130.10023.35
5.5.350.0130.07723.30
5.5.340.0130.09723.72
5.5.330.0230.07723.66
5.5.320.0130.09723.49
5.5.310.0070.10723.64
5.5.300.0130.09723.75
5.5.290.0070.09723.73
5.5.280.0030.10023.74
5.5.270.0030.06023.64
5.5.260.0100.10023.72
5.5.250.0100.09323.42
5.5.240.0100.09322.99
5.5.230.0100.07723.11
5.5.220.0170.05723.13
5.5.210.0070.05323.12
5.5.200.0130.04023.03
5.5.190.0000.06022.95
5.5.180.0100.04723.05
5.5.160.0070.09323.07
5.5.150.0070.05723.02
5.5.140.0130.08323.02
5.5.130.0000.08022.91
5.5.120.0030.06023.05
5.5.110.0130.04322.96
5.5.100.0070.05723.00
5.5.90.0070.05322.96
5.5.80.0030.05722.85
5.5.70.0100.04722.90
5.5.60.0000.05722.90
5.5.50.0100.04322.90
5.5.40.0030.05722.99
5.5.30.0000.05322.77
5.5.20.0030.05322.90
5.5.10.0000.05722.82
5.5.00.0100.04722.78
5.4.450.0300.11722.16
5.4.440.0030.06722.13
5.4.430.0000.11022.31
5.4.420.0030.08322.15
5.4.410.0100.09022.02
5.4.400.0070.05721.84
5.4.390.0100.06021.77
5.4.380.0070.05321.77
5.4.370.0030.04721.83
5.4.360.0070.05021.99
5.4.350.0000.05721.79
5.4.340.0030.06321.99
5.4.320.0070.08721.80
5.4.310.0030.07321.77
5.4.300.0030.07021.82
5.4.290.0030.05021.66
5.4.280.0070.05021.88
5.4.270.0030.09321.87
5.4.260.0030.06021.89
5.4.250.0100.07321.95
5.4.240.0130.04021.83
5.4.230.0130.05321.81
5.4.220.0030.06021.85
5.4.210.0070.04721.67
5.4.200.0070.05021.95
5.4.190.0000.05321.82
5.4.180.0030.05021.80
5.4.170.0030.05021.88
5.4.160.0070.04721.90
5.4.150.0000.05321.81
5.4.140.0100.04319.24
5.4.130.0130.04019.20
5.4.120.0000.04319.23
5.4.110.0100.05019.15
5.4.100.0000.05019.09
5.4.90.0100.04319.10
5.4.80.0070.06719.20
5.4.70.0070.04319.29
5.4.60.0130.06719.26
5.4.50.0030.08719.12
5.4.40.0130.09719.25
5.4.30.0070.09719.07
5.4.20.0130.05719.14
5.4.10.0170.08019.10
5.4.00.0100.10718.50
5.3.290.0030.09017.46
5.3.280.0000.05717.35
5.3.270.0030.05717.26
5.3.260.0000.05717.43
5.3.250.0100.04717.29
5.3.240.0000.06017.26
5.3.230.0000.05717.32
5.3.220.0070.05017.32
5.3.210.0000.05717.29
5.3.200.0030.06017.23
5.3.190.0030.05017.36
5.3.180.0100.04317.18
5.3.170.0100.06317.32
5.3.160.0100.05317.29
5.3.150.0070.10317.14
5.3.140.0070.10317.20
5.3.130.0070.07017.20
5.3.120.0100.07717.25
5.3.110.0230.08017.26
5.3.100.0100.09316.75
5.3.90.0170.08716.73
5.3.80.0100.06316.63
5.3.70.0030.09316.70
5.3.60.0170.08716.71
5.3.50.0100.09316.55
5.3.40.0030.10316.55
5.3.30.0070.08716.50
5.3.20.0030.06016.41
5.3.10.0030.07016.40
5.3.00.0130.08716.27
5.2.170.0070.09013.65
5.2.160.0100.05013.65
5.2.150.0070.08713.65
5.2.140.0030.05713.65
5.2.130.0070.09013.65
5.2.120.0100.08013.65
5.2.110.0070.06313.65
5.2.100.0030.07013.81
5.2.90.0000.07713.65
5.2.80.0170.06313.65
5.2.70.0030.05713.65
5.2.60.0130.06313.65
5.2.50.0100.08313.65
5.2.40.0030.06313.65
5.2.30.0030.08713.65
5.2.20.0030.04713.65
5.2.10.0000.04713.65
5.2.00.0030.09713.65
5.1.60.0030.07013.65
5.1.50.0070.08013.65
5.1.40.0070.08013.65
5.1.30.0130.09013.66
5.1.20.0070.05013.81
5.1.10.0100.09013.65
5.1.00.0030.08713.65
5.0.50.0070.09313.65
5.0.40.0000.06013.65
5.0.30.0000.09313.65
5.0.20.0000.08013.65
5.0.10.0000.08013.65
5.0.00.0100.10713.65
4.4.90.0130.05713.65
4.4.80.0100.09313.65
4.4.70.0030.06713.65
4.4.60.0000.05313.65
4.4.50.0070.08013.65
4.4.40.0130.08013.65
4.4.30.0030.10713.65
4.4.20.0070.08713.65
4.4.10.0100.05013.65
4.4.00.0030.08713.65
4.3.110.0000.09013.65
4.3.100.0030.04713.65
4.3.90.0030.06313.65
4.3.80.0000.12313.65
4.3.70.0030.08713.65
4.3.60.0000.08713.65
4.3.50.0000.11013.65
4.3.40.0000.12313.65
4.3.30.0030.10313.65
4.3.20.0070.08313.65
4.3.10.0030.10713.65
4.3.00.0000.08713.65

preferences:
35.27 ms | 401 KiB | 5 Q