3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** strrev function implementation taken from ext/standard/string.c PHP-5-5 branch http://lxr.php.net/xref/PHP_5_5/ext/standard/string.c#3165 // {{{ proto string strrev(string str) // Reverse a string PHP_FUNCTION(strrev) { char *str; char *e, *n, *p; int str_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } n = emalloc(str_len+1); p = n; e = str + str_len; while (--e>=str) { *p++ = *e; } *p = '\0'; RETVAL_STRINGL(n, str_len, 0); } // }}} */ // PHP Implementation function userland_strrev($string) { if (!is_string($string)) { return false; } $new_string = ""; $len = strlen($string); while (--$len > -1) { $new_string .= $string[$len]; } return $new_string; } $string = "Hello PHP!"; $c = 1000; $results = array(); $tests = array('strrev', 'userland_strrev'); foreach ($tests as $test) { for ($i = 0; $i < $c; $i++) { $t = microtime(true); $test($string); $results[$test][] = microtime(true) - $t; } $avg = array_sum($results[$test]) / count($results[$test]); printf("Average cost for function $test: %.6f ms\n", $avg); } // Without callable string resolution for ($i = 0; $i < $c; $i++) { $t = microtime(true); strrev($string); $results[$test][] = microtime(true) - $t; } $avg = array_sum($results[$test]) / count($results[$test]); printf("Average cost for function strrev: %.6f ms\n", $avg); for ($i = 0; $i < $c; $i++) { $t = microtime(true); userland_strrev($string); $results[$test][] = microtime(true) - $t; } $avg = array_sum($results[$test]) / count($results[$test]); printf("Average cost for function userland_strrev: %.6f ms\n", $avg);

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.10.0090.00915.38
7.4.00.0140.00615.00
7.3.130.0160.00615.03
7.3.120.0060.01514.73
7.3.110.0030.01714.72
7.3.100.0140.00015.22
7.3.90.0040.01415.06
7.3.80.0070.00715.15
7.3.70.0060.01314.82
7.3.60.0000.01114.98
7.3.50.0070.01014.73
7.3.40.0040.00715.08
7.3.30.0060.01214.92
7.3.20.0030.01316.80
7.3.10.0060.00916.42
7.3.00.0130.00316.71
7.2.260.0100.01015.37
7.2.250.0000.02115.20
7.2.240.0070.00715.06
7.2.230.0080.00415.48
7.2.220.0030.01515.44
7.2.210.0070.01114.75
7.2.200.0030.01315.21
7.2.190.0060.00615.22
7.2.180.0000.01115.47
7.2.170.0070.00715.02
7.2.160.0040.01115.36
7.2.150.0090.00917.17
7.2.140.0100.00616.77
7.2.130.0070.01116.85
7.2.120.0040.01417.06
7.2.110.0070.01016.90
7.2.100.0070.00717.20
7.2.90.0060.01116.76
7.2.80.0030.01316.40
7.2.70.0070.01016.86
7.2.60.0070.00716.65
7.2.50.0090.00617.04
7.2.40.0000.01416.94
7.2.30.0080.00816.63
7.2.20.0030.01317.12
7.2.10.0060.00916.95
7.2.00.0030.01118.19
7.1.330.0000.01615.91
7.1.320.0030.01415.65
7.1.310.0150.00315.96
7.1.300.0000.01815.76
7.1.290.0030.01415.84
7.1.280.0100.01015.65
7.1.270.0070.01415.57
7.1.260.0030.01615.69
7.1.250.0060.00915.87
7.1.240.0000.01615.82
7.1.230.0070.01015.76
7.1.220.0080.01215.77
7.1.210.0060.01215.84
7.1.200.0130.00315.61
7.1.190.0040.01415.82
7.1.180.0030.01015.80
7.1.170.0070.01315.91
7.1.160.0030.01615.67
7.1.150.0070.00715.72
7.1.140.0000.01815.64
7.1.130.0030.01315.96
7.1.120.0030.01515.82
7.1.110.0030.01415.84
7.1.100.0040.01116.04
7.1.90.0040.01515.81
7.1.80.0030.01315.48
7.1.70.0060.00716.63
7.1.60.0080.01617.68
7.1.50.0050.01716.56
7.1.40.0040.01615.83
7.1.30.0040.00815.84
7.1.20.0030.01415.79
7.1.10.0030.01615.98
7.1.00.0020.04919.19
7.0.330.0080.00815.08
7.0.320.0040.01115.39
7.0.310.0030.01315.32
7.0.300.0030.01615.57
7.0.290.0030.01415.32
7.0.280.0040.01515.34
7.0.270.0030.01015.59
7.0.260.0090.00615.36
7.0.250.0060.01515.33
7.0.240.0060.00915.55
7.0.230.0140.00415.35
7.0.220.0110.00315.55
7.0.210.0100.01015.61
7.0.200.0230.00915.25
7.0.190.0030.01215.16
7.0.180.0000.01515.35
7.0.170.0080.00415.21
7.0.160.0000.01215.27
7.0.150.0030.01615.35
7.0.140.0050.04318.82
7.0.130.0030.02015.42
7.0.120.0000.01715.16
7.0.110.0060.00915.52
7.0.100.0030.01415.28
7.0.90.0120.00915.61
7.0.80.0070.01015.26
7.0.70.0030.01015.57
7.0.60.0050.03917.75
7.0.50.0080.03516.89
7.0.40.0110.04616.79
7.0.30.0130.02316.79
7.0.20.0120.04916.70
7.0.10.0050.04516.82
7.0.00.0100.04816.83
5.6.400.0030.01814.65
5.6.390.0030.01714.83
5.6.380.0030.02014.82
5.6.370.0060.01815.02
5.6.360.0060.01614.91
5.6.350.0070.01715.11
5.6.340.0070.01315.23
5.6.330.0000.01915.18
5.6.320.0040.01815.17
5.6.310.0030.01814.93
5.6.300.0000.02215.08
5.6.290.0000.02215.04
5.6.280.0050.04818.34
5.6.270.0070.01315.11
5.6.260.0030.01614.66
5.6.250.0030.01914.75
5.6.240.0060.01614.82
5.6.230.0000.02514.99
5.6.220.0030.01714.89
5.6.210.0130.04818.06
5.6.200.0070.02816.91
5.6.190.0120.04017.86
5.6.180.0280.04218.04
5.6.170.0170.05017.90
5.6.160.0100.04717.98
5.6.150.0070.03716.80
5.6.140.0100.04616.88
5.6.130.0070.02816.73
5.6.120.0070.03318.11
5.6.110.0070.04518.27
5.6.100.0030.04818.27
5.6.90.0050.05518.24
5.6.80.0110.03617.86
5.6.70.0120.00614.64
5.6.60.0030.02114.71
5.6.50.0060.01514.84
5.6.40.0060.01315.14
5.6.30.0000.02314.88
5.6.20.0060.01614.81
5.6.10.0000.01615.00
5.6.00.0070.01414.92
5.5.380.0060.01914.96
5.5.370.0070.01114.94
5.5.360.0070.01115.05
5.5.350.2070.03317.95
5.5.340.0050.03216.74
5.5.330.0050.05517.84
5.5.320.0130.03317.99
5.5.310.0170.04817.76
5.5.300.0140.02016.79
5.5.290.0090.02516.63
5.5.280.0080.04218.14
5.5.270.0120.02318.02
5.5.260.0100.02918.20
5.5.250.0160.04317.88
5.5.240.0050.03217.88
5.5.230.0090.01614.53
5.5.220.0090.01214.95
5.5.210.0100.01314.63
5.5.200.0000.01714.76
5.5.190.0090.01514.97
5.5.180.0060.01214.70
5.5.170.0070.01015.19
5.5.160.0030.02114.74
5.5.150.0000.02314.73
5.5.140.0040.01814.52
5.5.130.0060.01215.07
5.5.120.0030.01615.00
5.5.110.0000.01514.98
5.5.100.0090.00914.90
5.5.90.0040.01514.94
5.5.80.0070.01714.85
5.5.70.0000.02014.46
5.5.60.0070.02514.91
5.5.50.0170.01414.52
5.5.40.0070.01414.66
5.5.30.0030.02314.82
5.5.20.0090.01214.60
5.5.10.0030.02014.30
5.5.00.0000.02214.58
5.4.450.0360.04015.74
5.4.440.0400.03415.76
5.4.430.0300.04115.76
5.4.420.0370.03715.78
5.4.410.0380.05615.76
5.4.400.0400.03315.43
5.4.390.0380.03915.67
5.4.380.0070.04715.58
5.4.370.0270.03415.22
5.4.360.0250.03615.46
5.4.350.0160.03815.29
5.4.340.0180.03315.38
5.4.330.0030.01011.62
5.4.320.0050.02912.31
5.4.310.0070.02812.48
5.4.300.0090.02712.37
5.4.290.0040.02912.15
5.4.280.0040.02912.21
5.4.270.0080.02812.22
5.4.260.0020.03312.35
5.4.250.0060.02812.29
5.4.240.0060.03612.14
5.4.230.0040.03112.13
5.4.220.0040.03312.30
5.4.210.0090.02412.09
5.4.200.0050.02812.21
5.4.190.0060.02912.23
5.4.180.0070.02612.27
5.4.170.0080.02712.28
5.4.160.0030.03012.17
5.4.150.0030.03112.17
5.4.140.0050.02612.06
5.4.130.0030.03112.31
5.4.120.0050.02712.10
5.4.110.0020.02912.13
5.4.100.0090.02712.14
5.4.90.0040.03312.17
5.4.80.0060.03112.18
5.4.70.0030.03212.08
5.4.60.0060.02512.10
5.4.50.0040.03312.07
5.4.40.0090.02511.93
5.4.30.0050.02712.01
5.4.20.0060.02712.11
5.4.10.0020.03111.93
5.4.00.0080.02511.74
5.3.290.0060.03012.33
5.3.280.0080.02612.21
5.3.270.0030.03212.15
5.3.260.0060.03112.26
5.3.250.0060.03012.27
5.3.240.0080.02812.20
5.3.230.0050.03112.20
5.3.220.0060.02912.13
5.3.210.0040.04112.13
5.3.200.0040.03412.13
5.3.190.0070.02812.22
5.3.180.0020.03312.27
5.3.170.0060.02812.24
5.3.160.0070.02512.28
5.3.150.0060.03312.27
5.3.140.0020.03312.23
5.3.130.0070.02612.15
5.3.120.0070.02712.28
5.3.110.0040.02912.24
5.3.100.0050.03111.93
5.3.90.0060.03111.86
5.3.80.0040.03111.85
5.3.70.0040.03411.88
5.3.60.0050.03011.91
5.3.50.0040.02811.88
5.3.40.0080.02711.86
5.3.30.0050.03011.94
5.3.20.0060.02611.75
5.3.10.0060.02711.67
5.3.00.0100.02411.67
5.2.170.0040.0389.71
5.2.160.0080.0339.71
5.2.150.0060.0369.71
5.2.140.0050.0389.71
5.2.130.0040.0379.67
5.2.120.0060.0349.66
5.2.110.0060.0359.67
5.2.100.0050.0359.66
5.2.90.0090.0319.66
5.2.80.0060.0379.66
5.2.70.0060.0369.65
5.2.60.0110.0319.61
5.2.50.0070.0509.58
5.2.40.0100.0499.56
5.2.30.0040.0569.52
5.2.20.0070.0539.51
5.2.10.0060.0389.41
5.2.00.0050.0369.28
5.1.60.0030.0348.82
5.1.50.0060.0318.81
5.1.40.0050.0318.80
5.1.30.0050.0349.15
5.1.20.0070.0329.17
5.1.10.0020.0378.89
5.1.00.0050.0348.89
5.0.50.0050.0347.39
5.0.40.0040.0327.24
5.0.30.0030.0467.05
5.0.20.0040.0337.02
5.0.10.0030.0337.00
5.0.00.0040.0456.99
4.4.90.0060.0435.40
4.4.80.0070.0315.39
4.4.70.0040.0325.38
4.4.60.0010.0355.38
4.4.50.0030.0395.40
4.4.40.0070.0405.39
4.4.30.0030.0335.39
4.4.20.0020.0355.45
4.4.10.0020.0335.45
4.4.00.0020.0445.42
4.3.110.0050.0325.32
4.3.100.0040.0315.31
4.3.90.0050.0365.32
4.3.80.0030.0485.32
4.3.70.0060.0345.31
4.3.60.0020.0385.32
4.3.50.0040.0395.32
4.3.40.0030.0495.27
4.3.30.0040.0444.08
4.3.20.0010.0384.06
4.3.10.0060.0354.01
4.3.00.0300.05710.55

preferences:
35.93 ms | 401 KiB | 5 Q