3v4l.org

run code in 300+ PHP versions simultaneously
<?php class UUID { /** * Generates version 1: MAC address */ public static function v1() { if (!function_exists('uuid_create')) return false; uuid_create(&$context); uuid_make($context, UUID_MAKE_V1); uuid_export($context, UUID_FMT_STR, &$uuid); return trim($uuid); } /** * Generates version 3 UUID: MD5 hash of URL */ public static function v3($i_url) { if (!function_exists('uuid_create')) return false; if (!strlen($i_url)) $i_url = self::v1(); uuid_create(&$context); uuid_create(&$namespace); uuid_make($context, UUID_MAKE_V3, $namespace, $i_url); uuid_export($context, UUID_FMT_STR, &$uuid); return trim($uuid); } /** * Generates version 4 UUID: random */ public static function v4() { if (!function_exists('uuid_create')) return false; uuid_create(&$context); uuid_make($context, UUID_MAKE_V4); uuid_export($context, UUID_FMT_STR, &$uuid); return trim($uuid); } /** * Generates version 5 UUID: SHA-1 hash of URL */ public static function v5($i_url) { if (!function_exists('uuid_create')) return false; if (!strlen($i_url)) $i_url = self::v1(); uuid_create(&$context); uuid_create(&$namespace); uuid_make($context, UUID_MAKE_V5, $namespace, $i_url); uuid_export($context, UUID_FMT_STR, &$uuid); return trim($uuid); } } ?> And here's a demonstration: <?php for ($i = 1; $i <= 3; ++$i) { echo 'microtime = ' . microtime(true) . '<br/>'; echo "V1 UUID: " . UUID::v1() . '<br/>'; echo "V3 UUID of URL='abc': " . UUID::v3('abc') . '<br/>'; echo "V4 UUID: " . UUID::v4() . '<br/>'; echo "V5 UUID of URL=null: " . UUID::v5(null) . '<br/>'; echo '<hr/>'; } ?>

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)
5.4.300.0060.03812.51
5.4.290.0130.03212.51
5.4.280.0050.03812.41
5.4.270.0110.03212.41
5.4.260.0080.03712.41
5.4.250.0100.03312.41
5.4.240.0070.03812.40
5.4.230.0060.03912.40
5.4.220.0080.03512.40
5.4.210.0070.05212.40
5.4.200.0080.04112.40
5.4.190.0060.05312.39
5.4.180.0050.04312.39
5.4.170.0090.05012.41
5.4.160.0080.04812.40
5.4.150.0090.03312.39
5.4.140.0040.03912.08
5.4.130.0080.04012.07
5.4.120.0050.03612.02
5.4.110.0040.03912.03
5.4.100.0050.04112.03
5.4.90.0050.03812.02
5.4.80.0060.03812.03
5.4.70.0110.03812.02
5.4.60.0070.05112.02
5.4.50.0080.05112.02
5.4.40.0060.04112.01
5.4.30.0060.04012.00
5.4.20.0120.03912.00
5.4.10.0100.03912.00
5.4.00.0060.03811.50
5.3.290.0050.04212.80
5.3.280.0070.04012.70
5.3.270.0060.04212.72
5.3.260.0050.04012.72
5.3.250.0080.03512.72
5.3.240.0070.04012.72
5.3.230.0050.04212.71
5.3.220.0070.05312.68
5.3.210.0070.04112.68
5.3.200.0120.03312.68
5.3.190.0070.03912.67
5.3.180.0050.04012.68
5.3.170.0100.04612.67
5.3.160.0060.04012.67
5.3.150.0040.04212.68
5.3.140.0100.03712.66
5.3.130.0090.05812.66
5.3.120.0080.06112.65
5.3.110.0090.05612.65
5.3.100.0090.05012.15
5.3.90.0030.05712.12
5.3.80.0080.05212.11
5.3.70.0070.05312.12

preferences:
140.31 ms | 1394 KiB | 7 Q