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: %.9f s\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: %.9f s\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: %.9f s\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.1.70.0000.00917.27
7.1.60.0090.01519.46
7.1.50.0070.02116.97
7.1.00.0000.08022.48
7.0.200.0380.01015.04
7.0.140.0100.07022.01
7.0.60.0130.06019.98
7.0.50.0000.04718.01
7.0.40.0070.07720.10
7.0.30.0200.04020.24
7.0.20.0230.07720.09
7.0.10.0170.03720.12
7.0.00.0100.08720.20
5.6.280.0000.08321.63
5.6.210.0000.09321.25
5.6.200.0100.08318.71
5.6.190.0130.08720.91
5.6.180.0470.07720.87
5.6.170.0330.07320.97
5.6.160.0130.08720.87
5.6.150.0030.08718.53
5.6.140.0070.07018.76
5.6.130.0070.04018.79
5.6.120.0130.06721.58
5.6.110.0130.05721.66
5.6.100.0030.08721.63
5.6.90.0100.08321.54
5.6.80.0030.07721.02
5.5.350.3400.05020.96
5.5.340.0070.05018.50
5.5.330.0070.08720.71
5.5.320.0270.08020.68
5.5.310.0230.04720.66
5.5.300.0030.08718.50
5.5.290.0000.07718.54
5.5.280.0100.08721.43
5.5.270.0000.04721.43
5.5.260.0130.08721.34
5.5.250.0070.08021.23
5.5.240.0200.02720.59
5.4.450.0670.06720.04
5.4.440.0930.09320.06
5.4.430.0770.06719.92
5.4.420.0170.05320.17
5.4.410.0830.05719.79
5.4.400.0400.05319.66
5.4.390.0200.05719.35
5.4.380.0330.05719.27
5.4.370.0800.06019.34
5.4.360.0530.07319.16
5.4.350.0200.06719.02
5.4.340.0400.06019.04
5.4.320.0090.04613.08
5.4.310.0070.05013.07
5.4.300.0100.03913.08
5.4.290.0080.04513.05
5.4.280.0080.05012.96
5.4.270.0100.05112.96
5.4.260.0090.05912.96
5.4.250.0080.04812.96
5.4.240.0100.05712.96
5.4.230.0090.04612.95
5.4.220.0110.03712.95
5.4.210.0090.04012.95
5.4.200.0060.04512.95
5.4.190.0070.04112.94
5.4.180.0090.04112.95
5.4.170.0110.03812.95
5.4.160.0060.04412.95
5.4.150.0080.04112.95
5.4.140.0060.04412.63
5.4.130.0080.04312.62
5.4.120.0070.04212.58
5.4.110.0030.04612.57
5.4.100.0070.04312.57
5.4.90.0090.04712.57
5.4.80.0060.04512.57
5.4.70.0100.03812.56
5.4.60.0060.04212.57
5.4.50.0080.04212.57
5.4.40.0050.04512.56
5.4.30.0090.04012.55
5.4.20.0120.03712.55
5.4.10.0060.04012.55
5.4.00.0050.04312.04
5.3.290.0080.04713.32
5.3.280.0060.04613.25
5.3.270.0030.05313.26
5.3.260.0080.04813.25
5.3.250.0090.04413.25
5.3.240.0050.04713.26
5.3.230.0070.04513.25
5.3.220.0100.06113.22
5.3.210.0100.07613.22
5.3.200.0060.04513.22
5.3.190.0100.04113.22
5.3.180.0050.05513.21
5.3.170.0060.04413.21
5.3.160.0110.05913.21
5.3.150.0080.05413.21
5.3.140.0090.04313.20
5.3.130.0100.04113.16
5.3.120.0080.05413.20
5.3.110.0060.04813.20
5.3.100.0060.04812.68
5.3.90.0030.04612.67
5.3.80.0050.04512.65
5.3.70.0090.04212.66
5.3.60.0100.04012.64
5.3.50.0100.03912.59
5.3.40.0080.04112.59
5.3.30.0060.04112.55
5.3.20.0060.04212.34
5.3.10.0060.05112.30
5.3.00.0070.04112.28
5.2.170.0050.0399.71
5.2.160.0080.0359.71
5.2.150.0060.0399.71
5.2.140.0060.0389.77
5.2.130.0060.0379.67
5.2.120.0070.0369.67
5.2.110.0060.0389.67
5.2.100.0050.0369.66
5.2.90.0040.0379.66
5.2.80.0080.0349.65
5.2.70.0040.0399.66
5.2.60.0070.0479.62
5.2.50.0070.0409.58
5.2.40.0050.0389.56
5.2.30.0030.0399.52
5.2.20.0070.0369.52
5.2.10.0070.0359.42
5.2.00.0060.0389.29
5.1.60.0060.0328.82
5.1.50.0040.0348.81
5.1.40.0060.0438.80
5.1.30.0100.0449.15
5.1.20.0050.0379.17
5.1.10.0110.0308.89
5.1.00.0080.0338.90
5.0.50.0050.0357.39
5.0.40.0030.0337.24
5.0.30.0050.0447.05
5.0.20.0020.0367.02
5.0.10.0040.0357.00
5.0.00.0070.0636.99
4.4.90.0040.0325.40
4.4.80.0030.0345.38
4.4.70.0050.0315.38
4.4.60.0020.0345.38
4.4.50.0080.0305.40
4.4.40.0030.0465.39
4.4.30.0040.0365.39
4.4.20.0070.0335.45
4.4.10.0030.0395.46
4.4.00.0040.0455.42
4.3.110.0050.0335.32
4.3.100.0030.0325.31
4.3.90.0050.0415.32
4.3.80.0060.0465.32
4.3.70.0040.0375.32
4.3.60.0060.0385.32
4.3.50.0030.0415.32
4.3.40.0030.0485.27
4.3.30.0030.0434.09
4.3.20.0030.0394.07
4.3.10.0030.0394.01
4.3.00.0230.02710.55

preferences:
32.43 ms | 401 KiB | 5 Q