~/docs
Resonate
Resonate
4.x 4.0.0, current 3.x 3.0.1 2.x 2.0.1 1.x 1.3.0
UUID Library
Toggle sidebar
UUID Library
webpatser/uuid 4.0.0

UUID Library 4.x

Performance

Measure UUID generation speed on your own hardware with Uuid::benchmark() and the bundled benchmark script.

The repository ships no published comparison data, only the claims in the README and the 1.2.1 changelog. The numbers on this page are measured on this server only. Speed depends on the PHP build and the machine, so measure it where it matters.

Uuid::benchmark()

use Webpatser\Uuid\Uuid;
 
$result = Uuid::benchmark(10000, 7);
 
print_r($result);
// version, iterations, total_time_ms, avg_time_us, memory_used_bytes, uuids_per_second

Uuid::benchmark(int $iterations = 10000, int $version = 7): array generates $iterations UUIDs of the given version and returns:

Key Meaning
version UUID version measured
iterations Number of UUIDs generated
total_time_ms Total time in milliseconds
avg_time_us Average time per UUID in microseconds
memory_used_bytes Change in memory_get_usage(true) over the run
uuids_per_second Throughput

For versions 3 and 5 the benchmark uses the name benchmark and Uuid::NS_DNS.

Run it live

Pick a version and an iteration count and run Uuid::benchmark() on this server. The figures are measured just now on this server's hardware. They are not a comparison with other libraries, and runs are rate limited per visitor.

Version Iterations

Runs on demand, at most 5 times a minute per visitor.

Benchmark script

examples/benchmark.php in the repository runs every version and prints a table:

php examples/benchmark.php 10000

The argument is the iteration count and defaults to 10000. If ramsey/uuid is installed, the script also compares v4 and v7 against it:

composer require --dev ramsey/uuid
php examples/benchmark.php 10000

The repository does not include benchmark data, so run the script before relying on any speed figure.

Choosing a version

  • v4 is purely random and needs no state.
  • v7 starts with a 48-bit millisecond timestamp, so values sort by creation time, which suits primary keys. Within one millisecond a per-process counter keeps up to 256 values in order; beyond 256 in one millisecond, or across processes, ordering is not guaranteed.
  • v3 and v5 hash the name on every call. Reuse the result instead of regenerating it.

Implementation notes

  • Random bytes come from Random\Randomizer.
  • Properties are readonly.
  • Version dispatch uses match.
  • There are no dependencies and no polyfills.