3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('TEST_LOOPS', 10); define('TEST_STRING', str_repeat('English+日に本ほん語ご', 16000)); //define('TEST_STRING', str_repeat('English', 16000)); //define('TEST_STRING', str_repeat('日に本ほん語ご', 16000)); error_reporting(-1); mb_internal_encoding('UTF-8'); function test($label, $callback) { $time = microtime(true); for ($i = 0; $i < TEST_LOOPS; $i++) { $callback(); } $duration = microtime(true) - $time; echo "{$label}: {$duration}s\n"; } test('preg_split+count', function() { $chars = preg_split('//u', TEST_STRING, -1, PREG_SPLIT_NO_EMPTY); $len = count($chars); for ($i = 0; $i < $len; $i++) { $char = $chars[$i]; // use $char } }); test('preg_split+foreach', function() { $chars = preg_split('//u', TEST_STRING, -1, PREG_SPLIT_NO_EMPTY); foreach ($chars as $char) { // use $char } }); test('preg_match_all', function() { if (preg_match_all('/./u', TEST_STRING, $matches)) { foreach ($matches[0] as $char) { // use $char } } });

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.3.90.2421.35530.45
7.3.80.1991.42230.53
7.3.70.2601.82930.95
7.3.60.3171.78230.80
7.3.50.2441.49530.99
7.3.40.3131.53430.93
7.3.30.2291.44130.69
7.3.20.3381.68330.89
7.3.10.3731.81131.08
7.3.00.4151.51131.08
7.2.220.2011.37630.87
7.2.210.2621.39731.08
7.2.200.2331.62631.11
7.2.190.3001.57631.10
7.2.180.2541.44531.30
7.2.170.2151.38531.21
7.2.160.2531.47731.14
7.2.150.4021.56731.03
7.2.140.3901.39031.25
7.2.130.4591.36731.06
7.2.120.4271.46631.22
7.2.110.4601.31031.18
7.2.100.4441.36031.01
7.2.90.5491.79031.44
7.2.80.5001.43331.10
7.2.70.4801.57931.27
7.2.60.6011.37231.24
7.2.50.4661.57531.22
7.2.40.4211.42031.29
7.2.30.4731.41131.07
7.2.20.4661.38131.29
7.2.10.5381.55531.34
7.2.00.4911.35230.98
7.1.320.3661.72430.09
7.1.310.3801.95830.23
7.1.300.4331.83030.20
7.1.290.4191.59529.82
7.1.280.4111.75629.97
7.1.270.4591.75630.29
7.1.260.3741.72030.12
7.1.250.3831.56630.25

preferences:
36.07 ms | 403 KiB | 5 Q