GuidConversionBench.php 997 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * This file is part of the ramsey/uuid library
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
  9. * @license http://opensource.org/licenses/MIT MIT
  10. */
  11. declare(strict_types=1);
  12. namespace Ramsey\Uuid\Benchmark;
  13. use Ramsey\Uuid\FeatureSet;
  14. use Ramsey\Uuid\Guid\Guid;
  15. use Ramsey\Uuid\UuidFactory;
  16. use Ramsey\Uuid\UuidInterface;
  17. final class GuidConversionBench
  18. {
  19. private const UUID_BYTES = [
  20. "\x1e\x94\x42\x33\x98\x10\x41\x38\x96\x22\x56\xe1\xf9\x0c\x56\xed",
  21. ];
  22. private UuidInterface $uuid;
  23. public function __construct()
  24. {
  25. $factory = new UuidFactory(new FeatureSet(useGuids: true));
  26. $this->uuid = $factory->fromBytes(self::UUID_BYTES[0]);
  27. assert($this->uuid instanceof Guid);
  28. }
  29. public function benchStringConversionOfGuid(): void
  30. {
  31. $this->uuid->toString();
  32. }
  33. }