3v4l.org

run code in 300+ PHP versions simultaneously
<?php // namespace AppBundle\Helper; /** * @author Bouchez Guillaume <guillaume.bouchez@infolegale.fr> */ class ShortIdGenerator { /* * Version du générateur */ const GENERATOR_VERSION = '1'; /** * Identifiant de version, prefix */ const GENERATOR_VERSION_PREFIX = 'a'; /** * @return string */ public static function generate() { $microtime = microtime(true); $numericId = intval(implode('', explode('.', $microtime))); $ret = self::numToAlpha($numericId, self::GENERATOR_VERSION_PREFIX); var_dump($numericId, $ret); return $ret; } /** * @see http://kvz.io/blog/2009/06/10/create-short-ids-with-php-like-youtube-or-tinyurl/ * @param mixed $in int, bigint input to translate * @param mixed $pad_up Number or boolean pads the result up to a specified length * @param string $pass_key Supplying a password makes it harder to calculate the original ID */ protected static function numToAlpha( $in, $prefix = '', $pad_up = false, $pass_key = null ) { $out = ''; $index = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $base = strlen($index); if ($pass_key !== null) { for ($n = 0; $n < strlen($index); $n++) { $i[] = substr($index, $n, 1); } $pass_hash = hash('sha256', $pass_key); $pass_hash = (strlen($pass_hash) < strlen($index) ? hash('sha512', $pass_key) : $pass_hash); for ($n = 0; $n < strlen($index); $n++) { $p[] = substr($pass_hash, $n, 1); } array_multisort($p, SORT_DESC, $i); $index = implode($i); } if (is_numeric($pad_up)) { $pad_up--; if ($pad_up > 0) { $in += pow($base, $pad_up); } } for ($t = ($in != 0 ? floor(log($in, $base)) : 0); $t >= 0; $t--) { $bcp = bcpow($base, $t); $a = floor($in / $bcp) % $base; $out = $out . substr($index, $a, 1); $in = $in - ($a * $bcp); } return $prefix.$out; } } ShortIdGenerator::generate();

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.2.00.0040.00819.52
7.1.100.0000.01218.36
7.1.70.1900.01015.51
7.1.60.2430.02033.53
7.1.50.1900.01733.36
7.1.40.2870.02032.85
7.1.30.0370.01732.81
7.1.20.0130.02032.92
7.1.10.0070.01715.08
7.1.00.0030.02014.93
7.0.200.2930.00715.18
7.0.190.2500.00315.14
7.0.180.0100.01014.54
7.0.170.0070.00714.65
7.0.160.3230.01714.78
7.0.150.0070.01314.66
7.0.140.0300.02314.77
7.0.130.0000.01714.88
7.0.120.0070.01314.75
7.0.110.0100.01014.81
7.0.100.0170.00314.73
7.0.90.3000.01314.50
7.0.80.2830.01714.79
7.0.70.0000.01714.62
7.0.60.0170.01714.48
7.0.50.0070.01314.73
7.0.40.0130.00714.90
7.0.30.0030.01314.74
7.0.20.0070.01314.59
7.0.10.0130.01314.69
7.0.00.0030.01314.80

preferences:
31.11 ms | 400 KiB | 5 Q