File: UuidGenerationBench.php

package info (click to toggle)
php-ramsey-uuid 4.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,124 kB
  • sloc: php: 13,359; xml: 194; python: 54; makefile: 16
file content (113 lines) | stat: -rw-r--r-- 2,917 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php

/**
 * This file is part of the ramsey/uuid library
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
 * @license http://opensource.org/licenses/MIT MIT
 */

declare(strict_types=1);

namespace Ramsey\Uuid\Benchmark;

use DateTimeImmutable;
use Ramsey\Uuid\Provider\Node\StaticNodeProvider;
use Ramsey\Uuid\Type\Hexadecimal;
use Ramsey\Uuid\Type\Integer as IntegerIdentifier;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

final class UuidGenerationBench
{
    /** @var Hexadecimal */
    private $node;
    /** @var int */
    private $clockSequence;
    /** @var IntegerIdentifier */
    private $localIdentifier;
    /** @var UuidInterface */
    private $namespace;

    public function __construct()
    {
        $this->node = (new StaticNodeProvider(new Hexadecimal('121212121212')))
            ->getNode();
        $this->clockSequence = 16383;
        $this->localIdentifier = new IntegerIdentifier(5);
        $this->namespace = Uuid::fromString('c485840e-9389-4548-a276-aeecd9730e50');
    }

    public function benchUuid1GenerationWithoutParameters(): void
    {
        Uuid::uuid1();
    }

    public function benchUuid1GenerationWithNode(): void
    {
        Uuid::uuid1($this->node);
    }

    public function benchUuid1GenerationWithNodeAndClockSequence(): void
    {
        Uuid::uuid1($this->node, $this->clockSequence);
    }

    public function benchUuid2GenerationWithDomainAndLocalIdentifier(): void
    {
        Uuid::uuid2(Uuid::DCE_DOMAIN_ORG, $this->localIdentifier);
    }

    public function benchUuid2GenerationWithDomainAndLocalIdentifierAndNode(): void
    {
        Uuid::uuid2(Uuid::DCE_DOMAIN_ORG, $this->localIdentifier, $this->node);
    }

    public function benchUuid2GenerationWithDomainAndLocalIdentifierAndNodeAndClockSequence(): void
    {
        Uuid::uuid2(Uuid::DCE_DOMAIN_ORG, $this->localIdentifier, $this->node, 63);
    }

    public function benchUuid3Generation(): void
    {
        Uuid::uuid3($this->namespace, 'name');
    }

    public function benchUuid4Generation(): void
    {
        Uuid::uuid4();
    }

    public function benchUuid5Generation(): void
    {
        Uuid::uuid5($this->namespace, 'name');
    }

    public function benchUuid6GenerationWithoutParameters(): void
    {
        Uuid::uuid6();
    }

    public function benchUuid6GenerationWithNode(): void
    {
        Uuid::uuid6($this->node);
    }

    public function benchUuid6GenerationWithNodeAndClockSequence(): void
    {
        Uuid::uuid6($this->node, $this->clockSequence);
    }

    public function benchUuid7Generation(): void
    {
        Uuid::uuid7();
    }

    public function benchUuid7GenerationWithDateTime(): void
    {
        Uuid::uuid7(new DateTimeImmutable('@1663203901.667000'));
    }
}