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; } // Tests $string = "Hello PHP!"; $c = 10000; // Without callable string resolution $results = array(); for ($i = 0; $i < $c; $i++) { $t = microtime(true); strrev($string); $results[$test][] = microtime(true) - $t; } array_shift($results[$test]); array_pop($results[$test]); $avg = array_sum($results[$test]) / count($results[$test]); printf("Average cost for function strrev: %.9f s\n", $avg); $results = array(); for ($i = 0; $i < $c; $i++) { $t = microtime(true); userland_strrev($string); $results[$test][] = microtime(true) - $t; } array_shift($results[$test]); array_pop($results[$test]); $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.4.00.0150.00315.01
7.3.120.0070.01014.89
7.3.110.0040.01514.93
7.3.100.0130.00314.89
7.3.90.0080.00415.08
7.3.80.0080.00414.67
7.3.70.0080.00414.54
7.3.60.0090.00614.88
7.3.50.0120.00614.71
7.3.40.0120.00414.91
7.3.30.0040.00814.77
7.3.20.0000.01316.70
7.3.10.0110.00416.65
7.3.00.0040.01116.64
7.2.250.0080.01215.32
7.2.240.0030.01914.88
7.2.230.0060.01215.26
7.2.220.0030.00715.26
7.2.210.0070.00714.95
7.2.200.0000.01514.93
7.2.190.0040.01115.03
7.2.180.0120.00815.05
7.2.170.0080.00815.12
7.1.330.0060.00915.49
7.1.320.0100.00315.72
7.1.310.0070.00315.89
7.1.300.0110.00615.77
7.1.290.0030.01415.96
7.1.280.0030.01415.53
7.1.270.0040.01115.80
7.1.260.0040.01215.83
7.1.70.0060.00617.11
7.1.60.0030.01719.46
7.1.50.0060.01617.20
7.0.200.0200.01014.52
5.4.290.3200.04019.13
5.4.280.3430.03719.02
5.4.270.4100.03319.12
5.4.260.3970.03719.09
5.4.250.3570.04319.00
5.4.240.4870.03719.10
5.4.230.3570.04019.36
5.4.220.3430.03719.11
5.4.210.3030.03319.23
5.4.200.3630.03319.32
5.4.190.3030.03318.86
5.4.180.3970.04319.14
5.4.170.3530.04318.96
5.4.160.3170.03719.09
5.4.150.3530.04018.96
5.4.140.3470.04016.40
5.4.130.3330.03316.44
5.4.120.3370.04316.73
5.4.110.3730.04016.42
5.4.100.3570.03716.48
5.4.90.3200.03316.54
5.4.80.3830.04016.61
5.4.70.3570.03716.61
5.4.60.3470.03316.61
5.4.50.3300.03016.61
5.4.40.3100.04016.46
5.4.30.3630.03016.48
5.4.20.3800.04716.49
5.4.10.3470.04016.36
5.4.00.3500.04015.98
5.3.280.4030.03314.60
5.3.270.3030.04014.60
5.3.260.3300.03314.73
5.3.250.3230.03314.45
5.3.240.3330.04014.53
5.3.230.3130.04314.43
5.3.220.3430.03314.38
5.3.210.3200.04014.49
5.3.200.3470.04014.57
5.3.190.3400.03714.49
5.3.180.3200.03314.46
5.3.170.3430.02714.40
5.3.160.3200.04314.45
5.3.150.3430.03314.46
5.3.140.3400.03314.70
5.3.130.3870.04314.68
5.3.120.3530.03314.44
5.3.110.3530.03314.56
5.3.100.3900.03713.96
5.3.90.3500.04313.86
5.3.80.3300.03313.78
5.3.70.3300.03014.09
5.3.60.1300.03314.07
5.3.50.1630.03313.90
5.3.40.2270.03313.80
5.3.30.2170.03313.74
5.3.20.2630.03313.59
5.3.10.1870.03313.55
5.3.00.2170.02713.71

preferences:
37.33 ms | 400 KiB | 5 Q