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); }

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.10.0030.01316.54
7.3.00.0070.01016.32
7.2.130.0100.01016.59
7.2.120.0070.01116.52
7.2.110.0100.01316.75
7.2.100.0040.00716.93
7.2.90.0090.00917.13
7.2.80.0070.01116.82
7.2.70.0100.00716.61
7.2.60.0080.00816.54
7.2.50.0090.01016.90
7.2.40.0070.01116.96
7.2.30.0150.01516.62
7.2.20.0110.01116.66
7.2.10.0120.00616.65
7.2.00.0080.01118.13
7.1.250.0070.00715.53
7.1.70.0030.01317.10
7.1.60.0160.01019.46
7.1.50.0110.01416.96
7.1.00.0030.08022.31
7.0.200.0340.00914.77
7.0.140.0000.07721.95
7.0.60.0070.08719.84
7.0.50.0030.08317.96
7.0.40.0130.06020.14
7.0.30.0270.03320.30
7.0.20.0200.08320.15
7.0.10.0070.08320.23
7.0.00.0000.04720.22
5.6.280.0030.07721.12
5.6.210.0070.08720.92
5.6.200.0070.08718.45
5.6.190.0070.04320.59
5.6.180.0470.07720.64
5.6.170.0330.05320.41
5.6.160.0030.06720.70
5.6.150.0100.08018.38
5.6.140.0170.07718.34
5.6.130.0000.04718.39
5.6.120.0170.07321.38
5.6.110.0100.08721.40
5.6.100.0130.04721.22
5.6.90.0070.04021.36
5.6.80.0100.05320.77
5.5.350.4100.04720.54
5.5.340.0130.06018.15
5.5.330.0100.08020.43
5.5.320.0230.05720.34
5.5.310.0300.07020.38
5.5.300.0070.04718.21
5.5.290.0070.04718.20
5.5.280.0030.04721.13
5.5.270.0130.04720.93
5.5.260.0100.03721.12
5.5.250.0100.08020.87
5.5.240.0070.07720.61
5.4.450.0700.06319.75
5.4.440.0830.06319.62
5.4.430.0270.06019.64
5.4.420.0630.06019.63
5.4.410.0630.06019.50
5.4.400.0700.05319.33
5.4.390.0570.06319.33
5.4.380.0370.05718.99
5.4.370.0100.07318.85
5.4.360.0370.07318.84
5.4.350.0300.06318.99
5.4.340.0430.06719.05
5.4.320.0060.03912.78
5.4.310.0090.04212.78
5.4.300.0060.04112.78
5.4.290.0080.04212.76
5.4.280.0050.04012.66
5.4.270.0100.03712.66
5.4.260.0080.04012.66
5.4.250.0070.04112.66
5.4.240.0030.04312.66
5.4.230.0080.04512.66
5.4.220.0100.03612.65
5.4.210.0050.03912.65
5.4.200.0100.04112.65
5.4.190.0060.04112.64
5.4.180.0100.05312.65
5.4.170.0100.05312.65
5.4.160.0110.04212.65
5.4.150.0060.06412.64
5.4.140.0180.07012.34
5.4.130.0140.06012.32
5.4.120.0090.04512.28
5.4.110.0060.03912.28
5.4.100.0060.03812.28
5.4.90.0120.03312.27
5.4.80.0080.05612.28
5.4.70.0070.05912.27
5.4.60.0090.05912.27
5.4.50.0080.03912.27
5.4.40.0050.05412.26
5.4.30.0090.03812.26
5.4.20.0100.04912.25
5.4.10.0060.05712.25
5.4.00.0090.05411.75
5.3.290.0070.04413.02
5.3.280.0100.05612.95
5.3.270.0100.05812.96
5.3.260.0060.06012.96
5.3.250.0060.04012.96
5.3.240.0090.03812.96
5.3.230.0120.04512.95
5.3.220.0090.04212.93
5.3.210.0080.04012.93
5.3.200.0070.04012.92
5.3.190.0080.04012.93
5.3.180.0050.04512.92
5.3.170.0060.04012.92
5.3.160.0040.04312.92
5.3.150.0130.05812.93
5.3.140.0090.07312.91
5.3.130.0060.04612.91
5.3.120.0080.04112.90
5.3.110.0070.04212.91
5.3.100.0080.04012.39
5.3.90.0050.04512.38
5.3.80.0110.04812.36
5.3.70.0080.05512.37
5.3.60.0100.05212.35
5.3.50.0090.04112.30
5.3.40.0100.04412.30
5.3.30.0050.04212.26
5.3.20.0120.05312.04
5.3.10.0110.06712.00
5.3.00.0080.03911.99
5.2.170.0060.0479.48
5.2.160.0080.0469.48
5.2.150.0100.0529.48
5.2.140.0110.0629.48
5.2.130.0110.0499.44
5.2.120.0080.0309.43
5.2.110.0100.0409.45
5.2.100.0090.0529.45
5.2.90.0050.0409.44
5.2.80.0060.0339.44
5.2.70.0070.0329.44
5.2.60.0030.0369.39
5.2.50.0020.0369.36
5.2.40.0060.0319.34
5.2.30.0090.0299.31
5.2.20.0060.0319.30
5.2.10.0050.0319.21
5.2.00.0050.0339.07
5.1.60.0070.0328.46
5.1.50.0050.0288.45
5.1.40.0020.0318.43
5.1.30.0080.0278.79
5.1.20.0060.0298.80
5.1.10.0060.0338.53
5.1.00.0030.0328.53
5.0.50.0020.0297.02
5.0.40.0040.0256.87
5.0.30.0030.0386.69
5.0.20.0020.0286.65
5.0.10.0030.0346.62
5.0.00.0050.0386.62
4.4.90.0050.0245.02
4.4.80.0040.0235.00
4.4.70.0050.0225.00
4.4.60.0050.0235.00
4.4.50.0030.0255.02
4.4.40.0070.0315.02
4.4.30.0020.0325.01
4.4.20.0040.0275.07
4.4.10.0040.0255.07
4.4.00.0040.0345.04
4.3.110.0010.0334.95
4.3.100.0010.0264.94
4.3.90.0050.0254.95
4.3.80.0040.0354.95
4.3.70.0030.0264.95
4.3.60.0020.0264.95
4.3.50.0060.0234.95
4.3.40.0060.0324.90
4.3.30.0020.0343.71
4.3.20.0020.0273.69
4.3.10.0020.0273.64
4.3.00.0030.05010.55

preferences:
37.96 ms | 401 KiB | 5 Q