3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('ITERATIONS', 1000); function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } function keywordsWithoutMatch() { return "value1|value2|cat|dog|Plan du scénario|Plan du Scénario"; } function keywordsWithMatch() { return "test|Lëtzebuergesch|Forgatókönyv|Pirate"; } $native = "Pirate"; function benchmarkInArray($native) { for ($i = 0; $i < ITERATIONS; $i++) { $keywordTypes = array( 'Given' => explode('|', keywordsWithoutMatch()), 'When' => explode('|', keywordsWithoutMatch()), 'Then' => explode('|', keywordsWithoutMatch()), 'And' => explode('|', keywordsWithoutMatch()), 'But' => explode('|', keywordsWithMatch()) ); foreach ($keywordTypes as $type => $keywords) { if (in_array($native, $keywords) || in_array($native . '<', $keywords)) { if ($type != 'But') throw new Exception(); break; } } } } function benchmarkInArrayWithCache($native) { $keywordTypes = array( 'Given' => explode('|', keywordsWithoutMatch()), 'When' => explode('|', keywordsWithoutMatch()), 'Then' => explode('|', keywordsWithoutMatch()), 'And' => explode('|', keywordsWithoutMatch()), 'But' => explode('|', keywordsWithMatch()) ); for ($i = 0; $i < ITERATIONS; $i++) { foreach ($keywordTypes as $type => $keywords) { if (in_array($native, $keywords) || in_array($native . '<', $keywords)) { if ($type != 'But') throw new Exception(); break; } } } } function benchmarkMbStrpos($native) { for ($i = 0; $i < ITERATIONS; $i++) { $keywordTypes = array( 'Given' => keywordsWithoutMatch(), 'When' => keywordsWithoutMatch(), 'Then' => keywordsWithoutMatch(), 'And' => keywordsWithoutMatch(), 'But' => keywordsWithMatch() ); foreach ($keywordTypes as $type => $keywords) { if (false !== mb_strpos($keywords, $native)) { if ($type != 'But') throw new Exception(); break; } } } } function benchmarkMbStrposWithCache($native) { $keywordTypes = array( 'Given' => keywordsWithoutMatch(), 'When' => keywordsWithoutMatch(), 'Then' => keywordsWithoutMatch(), 'And' => keywordsWithoutMatch(), 'But' => keywordsWithMatch() ); for ($i = 0; $i < ITERATIONS; $i++) { foreach ($keywordTypes as $type => $keywords) { if (false !== mb_strpos($keywords, $native)) { if ($type != 'But') throw new Exception(); break; } } } } $time_start = microtime_float(); benchmarkInArray($native); echo "benchmark in_array: " . (microtime_float() - $time_start) . "\n"; $time_start = microtime_float(); benchmarkInArrayWithCache($native); echo "benchmark in_array with cache: " . (microtime_float() - $time_start) . "\n"; $time_start = microtime_float(); benchmarkMbStrpos($native); echo "benchmark mb_strpos: " . (microtime_float() - $time_start) . "\n"; $time_start = microtime_float(); benchmarkMbStrposWithCache($native); echo "benchmark mb_strpos with cache: " . (microtime_float() - $time_start) . "\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.2.00.0000.01819.33
7.1.70.0000.01417.11
7.1.60.0030.02819.33
7.1.50.0160.01616.98
7.1.00.0170.07322.30
7.0.200.0100.01016.88
7.0.140.0000.09021.96
7.0.60.0030.08020.00
7.0.50.0070.07317.87
7.0.40.0070.04720.26
7.0.30.0230.06020.23
7.0.20.0370.08320.07
7.0.10.0030.08320.02
7.0.00.0100.09320.09
5.6.280.0100.09021.15
5.6.210.0000.10020.72
5.6.200.0130.08318.18
5.6.190.0030.08320.61
5.6.180.0270.05320.47
5.6.170.0300.06020.44
5.6.160.0170.09720.61
5.6.150.0100.09318.14
5.6.140.0100.06318.27
5.6.130.0100.08718.15
5.6.120.0070.09321.03
5.6.110.0170.08321.14
5.6.100.0130.09721.02
5.6.90.0100.10321.04
5.6.80.0030.09320.55
5.5.350.0070.11020.34
5.5.340.0100.08318.07
5.5.330.0070.11720.34
5.5.320.3100.06020.38
5.5.310.0400.11020.30
5.5.300.0070.11017.99
5.5.290.0130.11318.01
5.5.280.0100.12020.79
5.5.270.0070.08320.88
5.5.260.0100.11020.82
5.5.250.0070.11020.69
5.5.240.0070.11720.29
5.4.450.0000.06319.57
5.4.440.0070.06319.57
5.4.430.0930.08319.30
5.4.420.1670.06019.59
5.4.410.1630.05319.40
5.4.400.1530.06018.98
5.4.390.1470.06319.23
5.4.380.1600.08319.09
5.4.370.1970.05019.30
5.4.360.1670.05718.99
5.4.350.1630.06319.31
5.4.340.0130.07018.98
5.4.320.0000.06318.86
5.4.310.0030.07319.09
5.4.300.1470.06018.86
5.4.290.1700.05719.08
5.4.280.1470.05719.09
5.4.270.1430.05719.20
5.4.260.1500.06019.22
5.4.250.1600.05718.83
5.4.240.1530.06319.16
5.4.230.1600.06019.16
5.4.220.1430.06319.15
5.4.210.0130.06019.05
5.4.200.0000.06019.14
5.4.190.0430.06719.30
5.4.180.1470.06019.21
5.4.170.1530.06018.82
5.4.160.1900.05718.82
5.4.150.1600.05718.98
5.4.140.1800.07016.50
5.4.130.1500.05716.54
5.4.120.1670.05316.41
5.4.110.1870.06716.50
5.4.100.1470.06316.60
5.4.90.1730.06316.50
5.4.80.1700.06716.48
5.4.70.1200.06716.62
5.4.60.1700.07016.50
5.4.50.2070.05716.51
5.4.40.1670.07016.36
5.4.30.2070.06316.48
5.4.20.1700.06716.39
5.4.10.1470.05016.54
5.4.00.1500.06716.13
5.3.290.0000.11714.63
5.3.280.0030.06014.79
5.3.270.1000.06014.73
5.3.260.1670.05314.55
5.3.250.1700.07014.73
5.3.240.1870.09314.62
5.3.230.1630.06714.72
5.3.220.1670.07014.66
5.3.210.1600.06314.69
5.3.200.1870.07314.50
5.3.190.1600.06014.63
5.3.180.0030.05714.61
5.3.170.0030.05714.74
5.3.160.0200.07714.66
5.3.150.2000.07314.83
5.3.140.2000.09714.68
5.3.130.1630.05314.51
5.3.120.1570.06314.49
5.3.110.1530.06314.64
5.3.100.1730.05714.11
5.3.90.1470.06714.11
5.3.80.1670.06014.06
5.3.70.1470.05314.11
5.3.60.0000.06313.95
5.3.50.0070.07013.90
5.3.40.0730.05714.07
5.3.30.1670.05313.88
5.3.20.1730.05713.85
5.3.10.1600.05313.86
5.3.00.1700.05713.59
5.2.170.1370.06011.29
5.2.160.1300.05011.27
5.2.150.1500.07011.12
5.2.140.1300.06311.27
5.2.130.1270.05311.30
5.2.120.0000.06711.16
5.2.110.0030.08711.22
5.2.100.0070.08711.17
5.2.90.1330.06711.07
5.2.80.1400.05011.17
5.2.70.1300.04311.08
5.2.60.1470.04711.02
5.2.50.1530.05311.07
5.2.40.1200.04710.98
5.2.30.1200.06010.93
5.2.20.1070.04711.01
5.2.10.1030.04310.84
5.2.00.1100.05310.75
5.1.60.0570.04010.02
5.1.50.0000.05710.00
5.1.40.0030.0779.98
5.1.30.0030.06010.52
5.1.20.0870.06010.38
5.1.10.1000.04710.04
5.1.00.1230.05710.09
5.0.50.0670.0639.31
5.0.40.0630.0539.31
5.0.30.0630.0739.31
5.0.20.0630.0539.31
5.0.10.0570.0439.31
5.0.00.0600.0779.31
4.4.90.0630.0179.31
4.4.80.0670.0239.31
4.4.70.0600.0179.31
4.4.60.0570.0239.31
4.4.50.0570.0139.31
4.4.40.0500.0279.31
4.4.30.0500.0309.31
4.4.20.0030.0139.31
4.4.10.0000.0239.31
4.4.00.0000.0539.31
4.3.110.0000.0239.31
4.3.100.0000.0209.31
4.3.90.0000.0179.31
4.3.80.0000.0479.31
4.3.70.0000.0139.31
4.3.60.0270.0239.31
4.3.50.0630.0279.31
4.3.40.0700.0309.31
4.3.30.0300.0239.31
4.3.20.0300.0279.31
4.3.10.0300.0209.31
4.3.00.0300.0239.31

preferences:
55.47 ms | 400 KiB | 5 Q