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.4.00.0060.00915.08
7.3.120.0100.00714.67
7.3.110.0060.01314.81
7.3.100.0140.00314.83
7.3.90.0080.00815.05
7.3.80.0070.01014.95
7.3.70.0100.00314.62
7.3.60.0040.01114.87
7.3.50.0130.00014.92
7.3.40.0030.00614.62
7.3.30.0060.00914.70
7.3.20.0040.00716.81
7.3.10.0030.01216.66
7.3.00.0090.00816.67
7.2.250.0030.01615.39
7.2.240.0150.00614.81
7.2.230.0100.00715.00
7.2.220.0040.00815.08
7.2.210.0030.01015.00
7.2.200.0100.00715.09
7.2.190.0070.00715.20
7.2.180.0070.00714.86
7.2.170.0070.00714.89
7.2.130.0080.00616.88
7.2.120.0070.00916.86
7.2.110.0070.00616.96
7.2.100.0050.01116.84
7.2.90.0040.01316.91
7.2.80.0100.00617.03
7.2.70.0040.01317.00
7.2.60.0080.00816.98
7.2.50.0080.00516.87
7.2.40.0050.01216.84
7.2.30.0130.00316.79
7.2.20.0100.00816.73
7.2.10.0090.00716.87
7.2.00.0050.01117.74
7.1.330.0060.01115.72
7.1.320.0000.01715.86
7.1.310.0030.01015.60
7.1.300.0060.01315.60
7.1.290.0060.00615.62
7.1.280.0030.01215.82
7.1.270.0030.01715.98
7.1.260.0040.00715.65
7.1.250.0090.00515.70
7.1.240.0090.00915.53
7.1.230.0030.01015.88
7.1.220.0100.01015.88
7.1.210.0080.00815.46
7.1.200.0070.01415.80
7.1.190.0060.01215.95
7.1.180.0080.01215.84
7.1.170.0110.00715.69
7.1.160.0090.00615.62
7.1.150.0070.01415.63
7.1.140.0100.01015.80
7.1.130.0140.00715.54
7.1.120.0060.01315.91
7.1.110.0070.01015.70
7.1.100.0000.01415.83
7.1.90.0040.01215.83
7.1.80.0150.00315.75
7.1.70.0020.01016.52
7.1.60.0110.01117.70
7.1.50.0050.01416.42
7.1.40.0080.01216.02
7.1.30.0090.01315.84
7.1.20.0170.00715.72
7.1.10.0120.00915.50
7.1.00.0060.04419.05
7.0.330.0110.00715.20
7.0.320.0090.00615.33
7.0.310.0120.00415.39
7.0.300.0120.00615.36
7.0.290.0100.01015.45
7.0.280.0070.01115.29
7.0.270.0060.00915.16
7.0.260.0110.01515.16
7.0.250.0070.01015.44
7.0.240.0100.01015.38
7.0.230.0100.00715.23
7.0.220.0110.00315.28
7.0.210.0070.01115.37
7.0.200.0130.00915.05
7.0.190.0060.00915.43
7.0.180.0100.00715.29
7.0.170.0160.00315.39
7.0.160.0100.01015.46
7.0.150.0030.01415.49
7.0.140.0040.04418.76
7.0.130.0120.00615.28
7.0.120.0070.00715.26
7.0.110.0140.00715.46
7.0.100.0030.01315.35
7.0.90.0100.01015.22
7.0.80.0090.00915.09
7.0.70.0040.01615.32
7.0.60.0080.02517.69
7.0.50.0080.02216.66
7.0.40.0050.02916.64
7.0.30.0190.04516.73
7.0.20.0220.03816.61
7.0.10.0060.02816.72
7.0.00.0030.03616.80
5.6.380.0030.01014.24
5.6.370.0070.00714.25
5.6.360.0040.01813.75
5.6.350.0120.01214.38
5.6.340.0040.01314.09
5.6.330.0030.02014.30
5.6.320.0100.00714.48
5.6.310.0100.01414.51
5.6.300.0030.01914.26
5.6.290.0120.01513.78
5.6.280.0040.01213.74
5.6.270.0040.01314.25
5.6.260.0140.00714.04
5.6.250.0070.01114.25
5.6.240.0070.01313.95
5.6.230.0030.01314.30
5.6.220.0120.01014.27
5.6.210.0060.02817.26
5.6.200.0030.05016.19
5.6.190.0050.02917.21
5.6.180.0120.04117.39
5.6.170.0150.03617.38
5.6.160.0100.04717.46
5.6.150.0040.03116.34
5.6.140.0080.04916.26
5.6.130.0050.05416.17
5.6.120.0070.03517.62
5.6.110.0100.04917.50
5.6.100.0030.05217.66
5.6.90.0120.04517.67
5.6.80.0080.04217.38
5.6.70.0130.00714.33
5.6.60.0030.01214.50
5.6.50.0030.01714.35
5.6.40.0000.01513.99
5.6.30.0000.01314.46
5.6.20.0030.01614.23
5.6.10.0070.01413.93
5.6.00.0000.01414.04
5.5.380.0000.01311.06
5.5.370.0030.01011.06
5.5.360.0060.00911.06
5.5.350.0100.02515.77
5.5.340.0070.04514.60
5.5.330.0070.03815.73
5.5.320.0130.04915.79
5.5.310.0110.03215.65
5.5.300.0000.03414.50
5.5.290.0070.04214.63
5.5.280.0050.02515.92
5.5.270.0050.02815.89
5.5.260.0050.04715.95
5.5.250.0100.04315.81
5.5.240.0030.04415.63
5.5.230.0060.00911.06
5.5.220.0000.01011.06
5.5.210.0090.00911.06
5.5.200.0000.01311.06
5.5.190.0060.00911.35
5.5.180.0030.01611.32
5.5.170.0000.01511.13
5.5.160.0070.01011.06
5.5.150.0030.00711.18
5.5.140.0040.01111.06
5.5.130.0030.01411.20
5.5.120.0030.01311.29
5.5.110.0000.01611.06
5.5.100.0070.00711.06
5.5.90.0030.01311.06
5.5.80.0060.01311.13
5.5.70.0030.01011.25
5.5.60.0030.01011.29
5.5.50.0030.00611.16
5.5.40.0000.01911.06
5.5.30.0070.00711.06
5.5.20.0030.01611.06
5.5.10.0040.01111.10
5.5.00.0090.00911.19
5.4.450.0340.03615.36
5.4.440.0470.02815.50
5.4.430.0200.04015.26
5.4.420.0400.03615.29
5.4.410.0370.03615.31
5.4.400.0430.02815.11
5.4.390.0300.03215.10
5.4.380.0120.03515.07
5.4.370.0200.03414.84
5.4.360.0160.03314.93
5.4.350.0170.03414.84
5.4.340.0250.03314.81
5.4.330.0030.00811.17
5.4.320.0050.02511.90
5.4.310.0070.03411.87
5.4.300.0050.02711.94
5.4.290.0030.02911.77
5.4.280.0030.02811.77
5.4.270.0070.02211.89
5.4.260.0020.02911.84
5.4.250.0040.02911.72
5.4.240.0060.02411.72
5.4.230.0050.02611.88
5.4.220.0040.02611.72
5.4.210.0080.02211.72
5.4.200.0040.03511.72
5.4.190.0050.02911.74
5.4.180.0050.02311.78
5.4.170.0040.02311.72
5.4.160.0030.02711.78
5.4.150.0040.02611.78
5.4.140.0040.02511.61
5.4.130.0020.02811.65
5.4.120.0060.02211.66
5.4.110.0090.02311.71
5.4.100.0090.03011.59
5.4.90.0080.03211.69
5.4.80.0090.03211.65
5.4.70.0050.03511.53
5.4.60.0050.02511.60
5.4.50.0070.02211.57
5.4.40.0020.03211.65
5.4.30.0020.02711.54
5.4.20.0100.02111.63
5.4.10.0030.02511.59
5.4.00.0040.02711.35
5.3.290.0040.03311.93
5.3.280.0080.02211.89
5.3.270.0060.02811.89
5.3.260.0040.02911.89
5.3.250.0050.02711.89
5.3.240.0040.02411.89
5.3.230.0060.02511.88
5.3.220.0080.02211.87
5.3.210.0030.03211.87
5.3.200.0060.02811.87
5.3.190.0090.02611.87
5.3.180.0040.02911.87
5.3.170.0060.02411.87
5.3.160.0060.02611.87
5.3.150.0040.02511.87
5.3.140.0070.02511.86
5.3.130.0070.02511.86
5.3.120.0060.02611.86
5.3.110.0040.02811.86
5.3.100.0020.02611.59
5.3.90.0040.02511.58
5.3.80.0050.02411.58
5.3.70.0050.02411.58
5.3.60.0070.02911.57
5.3.50.0050.02411.55
5.3.40.0030.02511.54
5.3.30.0070.02211.52
5.3.20.0060.02311.42
5.3.10.0050.02311.40
5.3.00.0050.02911.39
5.2.170.0070.02310.14
5.2.160.0050.02210.14
5.2.150.0020.02710.14
5.2.140.0070.02010.14
5.2.130.0050.02110.12
5.2.120.0020.02510.12
5.2.110.0060.02510.12
5.2.100.0080.02010.12
5.2.90.0050.01910.12
5.2.80.0050.02610.12
5.2.70.0050.02110.12
5.2.60.0060.02110.10
5.2.50.0040.02010.08
5.2.40.0020.02210.07
5.2.30.0060.01910.06
5.2.20.0020.02410.05
5.2.10.0050.02210.00
5.2.00.0040.0249.94
5.1.60.0060.0169.58
5.1.50.0050.0209.59
5.1.40.0020.0209.57
5.1.30.0050.0239.75
5.1.20.0070.0229.76
5.1.10.0070.0199.62
5.1.00.0040.0199.62
5.0.50.0020.0238.86
5.0.40.0020.0208.79
5.0.30.0050.0258.70
5.0.20.0030.0248.68
5.0.10.0020.0248.67
5.0.00.0030.0258.67
4.4.90.0030.0207.92
4.4.80.0020.0227.91
4.4.70.0040.0217.91
4.4.60.0010.0317.91
4.4.50.0020.0287.92
4.4.40.0020.0287.88
4.4.30.0060.0177.91
4.4.20.0060.0207.95
4.4.10.0020.0237.96
4.4.00.0040.0247.91
4.3.110.0030.0207.87
4.3.100.0050.0457.87
4.3.90.0150.0507.85
4.3.80.0010.0297.84
4.3.70.0020.0237.85
4.3.60.0030.0247.84
4.3.50.0040.0287.85
4.3.40.0040.0267.81
4.3.30.0030.0227.21
4.3.20.0010.0237.20
4.3.10.0030.0237.18
4.3.00.0030.02310.80

preferences:
32.66 ms | 401 KiB | 5 Q