Пример #1
0
    $x = (string) \Ramsey\Uuid\Uuid::uuid4();
}
$results['ramsey-pecl'] = $watch->stop('ramsey-pecl');
$watch->start('ramsey-nopecl');
for ($i = 0; $i < ITERATIONS; ++$i) {
    \Ramsey\Uuid\Uuid::setFactory(new \Ramsey\Uuid\UuidFactory());
    $x = (string) \Ramsey\Uuid\Uuid::uuid4();
}
$results['ramsey-nopecl'] = $watch->stop('ramsey-nopecl');
$watch->start('ramsey-randomlib');
for ($i = 0; $i < ITERATIONS; ++$i) {
    $uuidFactory = new \Ramsey\Uuid\UuidFactory();
    // Using low-strength generator by default
    $uuidFactory->setRandomGenerator(new \Ramsey\Uuid\Generator\RandomLibAdapter());
    \Ramsey\Uuid\Uuid::setFactory($uuidFactory);
    $x = (string) \Ramsey\Uuid\Uuid::uuid4();
}
$results['ramsey-randomlib'] = $watch->stop('ramsey-randomlib');
if (PHP_MAJOR_VERSION >= 7) {
    $watch->start('ramsey-php7');
    for ($i = 0; $i < ITERATIONS; ++$i) {
        $uuidFactory = new \Ramsey\Uuid\UuidFactory();
        $uuidFactory->setRandomGenerator(new \Ramsey\Uuid\Benchmark\Php7Generator());
        \Ramsey\Uuid\Uuid::setFactory($uuidFactory);
        $x = (string) \Ramsey\Uuid\Uuid::uuid4();
    }
    $results['ramsey-php7'] = $watch->stop('ramsey-php7');
}
foreach ($results as $name => $result) {
    printf('% 16s | %.04f sec/%d | %.07f sec/one' . PHP_EOL, strtoupper($name), $result->getDuration() / 1000, ITERATIONS, $result->getDuration() / 1000 / ITERATIONS);
}
Пример #2
0
$results['pecl'] = $watch->stop('pecl');
/**
 * Using the older Rhumsaa\Uuid version of the library
 */
$watch->start('rhumsaa');
for ($i = 0; $i < ITERATIONS; ++$i) {
    $x = (string) \Rhumsaa\Uuid\Uuid::uuid1();
}
$results['rhumsaa'] = $watch->stop('rhumsaa');
/**
 * Using Ramsey\Uuid with default time generator
 */
$watch->start('ramsey-default');
for ($i = 0; $i < ITERATIONS; ++$i) {
    $x = (string) \Ramsey\Uuid\Uuid::uuid1();
}
$results['ramsey-default'] = $watch->stop('ramsey-default');
/**
 * Using Ramsey\Uuid with a pecl-uuid time generator
 */
$watch->start('ramsey-pecl');
$uuidFactory = new \Ramsey\Uuid\UuidFactory();
$uuidFactory->setTimeGenerator(new \Ramsey\Uuid\Generator\PeclUuidTimeGenerator());
\Ramsey\Uuid\Uuid::setFactory($uuidFactory);
for ($i = 0; $i < ITERATIONS; ++$i) {
    $x = (string) \Ramsey\Uuid\Uuid::uuid1();
}
$results['ramsey-pecl'] = $watch->stop('ramsey-pecl');
foreach ($results as $name => $result) {
    printf('% 24s | %.04f sec/%d | %.07f sec/one' . PHP_EOL, strtoupper($name), $result->getDuration() / 1000, ITERATIONS, $result->getDuration() / 1000 / ITERATIONS);
}
Пример #3
0
$uuidFactory->setRandomGenerator(new \Ramsey\Uuid\Generator\MtRandGenerator());
\Ramsey\Uuid\Uuid::setFactory($uuidFactory);
for ($i = 0; $i < ITERATIONS; ++$i) {
    $x = (string) \Ramsey\Uuid\Uuid::uuid4();
}
$results['ramsey-mtrand'] = $watch->stop('ramsey-mtrand');
/**
 * Using Ramsey\Uuid with pecl-uuid
 */
$watch->start('ramsey-pecl');
$uuidFactory = new \Ramsey\Uuid\UuidFactory();
$uuidFactory->setRandomGenerator(new \Ramsey\Uuid\Generator\PeclUuidRandomGenerator());
\Ramsey\Uuid\Uuid::setFactory($uuidFactory);
for ($i = 0; $i < ITERATIONS; ++$i) {
    $x = (string) \Ramsey\Uuid\Uuid::uuid4();
}
$results['ramsey-pecl'] = $watch->stop('ramsey-pecl');
/**
 * Using Ramsey\Uuid with ircmaxell/random-lib
 */
$watch->start('ramsey-randomlib');
$uuidFactory = new \Ramsey\Uuid\UuidFactory();
$uuidFactory->setRandomGenerator(new \Ramsey\Uuid\Generator\RandomLibAdapter());
\Ramsey\Uuid\Uuid::setFactory($uuidFactory);
for ($i = 0; $i < ITERATIONS; ++$i) {
    $x = (string) \Ramsey\Uuid\Uuid::uuid4();
}
$results['ramsey-randomlib'] = $watch->stop('ramsey-randomlib');
foreach ($results as $name => $result) {
    printf('% 21s | %.04f sec/%d | %.07f sec/one' . PHP_EOL, strtoupper($name), $result->getDuration() / 1000, ITERATIONS, $result->getDuration() / 1000 / ITERATIONS);
}