3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php var_dump(encodeFloat(1.1234567890123456, 13)); function encodeFloat($float, $precision) { $precision = max(1, (int) $precision); $log = (int) floor(log(abs($float), 10)); if (abs($float) < 9007199254740992.0 && $log > -5 && abs($log) < $precision) { return $this->formatFloat($float, $precision - $log - 1); } // Deal with overflow that results from rounding $log += (int) (round(abs($float) / pow(10, $log), $precision - 1) / 10); $string = $this->formatFloat($float / pow(10, $log), $precision - 1); return sprintf('%sE%+d', $string, $log); } function formatFloat($float, $digits) { $digits = max((int) $digits, 1); $string = rtrim(number_format($float, $digits, '.', ''), '0'); return substr($string, -1) === '.' ? $string . '0' : $string; }
based on 3iFaO

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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.2.60.0030.01016.91
7.2.00.0000.01419.84
7.1.200.0000.01215.81
7.1.100.0000.00918.54
7.1.70.0070.00017.44
7.1.60.0060.01919.11
7.1.50.0170.00717.39
7.1.00.0100.07022.64
7.0.200.0070.00317.06
7.0.60.0100.07720.29
7.0.50.0000.04318.11
7.0.40.0100.04020.52
7.0.30.0270.08320.51
7.0.20.0330.06320.35
7.0.10.0070.05720.52
7.0.00.0030.06020.45
5.6.280.0000.05321.13
5.6.210.0100.07720.86
5.6.200.0100.04318.45
5.6.190.0000.05020.78
5.6.180.0470.07720.78
5.6.170.0270.08020.75
5.6.160.0000.09020.80
5.6.150.0070.08018.46
5.6.140.0100.06318.52
5.6.130.0100.05018.43
5.6.120.0070.07021.29
5.6.110.0070.07021.37
5.6.100.0130.07321.30
5.6.90.0100.07321.25
5.6.80.0000.04720.70
5.5.350.0070.07320.74
5.5.340.0130.04318.21
5.5.330.0130.08320.82
5.5.320.0500.07020.53
5.5.310.0230.05020.64
5.5.300.0130.05718.30
5.5.290.0030.08718.20
5.5.280.0070.06021.07
5.5.270.0070.04321.05
5.5.260.0170.05321.16
5.5.250.0000.09720.97
5.5.240.0070.08020.32
5.4.450.0800.06319.66
5.4.440.0900.06019.63
5.4.430.0700.06319.39
5.4.420.0930.04719.63
5.4.410.0900.05019.21
5.4.400.0770.06019.14
5.4.390.0730.06319.00
5.4.380.0830.05319.13
5.4.370.0930.05319.35
5.4.360.0870.05319.48
5.4.350.0800.05319.33
5.4.340.0770.04719.00
5.4.320.0630.05019.41
5.4.310.0630.05019.35
5.4.300.0700.05319.30
5.4.290.0600.05719.36
5.4.280.0630.05319.16
5.4.270.0700.04719.30
5.4.260.0700.04719.07
5.4.250.0630.05319.34
5.4.240.0830.03719.40
5.4.230.0700.04719.21
5.4.220.0600.05718.92
5.4.210.0930.04319.20
5.4.200.0670.05019.32
5.4.190.0930.04018.91
5.4.180.0770.05319.47
5.4.170.0800.05319.19
5.4.160.0800.05719.05
5.4.150.0900.04719.32
5.4.140.0770.06016.48
5.4.130.0770.05716.64
5.4.120.0970.05316.43
5.4.110.0870.04716.68
5.4.100.0800.05016.80
5.4.90.0830.04716.39
5.4.80.0770.05316.68
5.4.70.0170.04016.88
5.4.60.0300.06316.59
5.4.50.0100.04316.57
5.4.40.0270.06716.74
5.4.30.0270.02716.79
5.4.20.0270.05316.82
5.3.290.4330.03315.04
5.3.280.4370.03714.93
5.3.270.3300.04014.89
5.3.260.3570.04014.79
5.3.250.0270.04014.98
5.3.240.3170.03714.85
5.3.230.0100.04714.85
5.3.220.0200.04014.84
5.3.210.3770.03714.84
5.3.200.3030.03714.82
5.3.190.3570.04014.72
5.3.180.0130.04314.81