b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / a / home / dev2.destoffenstraat.com / vendor / jms / serializer / tests /
Filename/home/a/home/dev2.destoffenstraat.com/vendor/jms/serializer/tests/benchmark.php
Size1.64 kb
Permissionrw-r--r--
Ownerroot : root
Create time21-Aug-2025 12:26
Last modified22-Feb-2020 21:59
Last accessed22-Aug-2025 18:27
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

if (!isset($_SERVER['argv'][1], $_SERVER['argv'][2])) {
echo 'Usage: php benchmark.php <format> <iterations> [output-file]' . PHP_EOL;
exit(1);
}

list(, $format, $iterations) = $_SERVER['argv'];

require_once 'bootstrap.php';

function benchmark(\Closure $f, $times = 10)
{
$time = microtime(true);
for ($i = 0; $i < $times; $i++) {
$f();
}

return (microtime(true) - $time) / $times;
}

function createCollection()
{
$collection = array();
for ($i = 0; $i < 200; $i++) {
$collection[] = createObject();
}

return $collection;
}

function createObject()
{
$p = new \JMS\Serializer\Tests\Fixtures\Publisher('bar');
$post = new \JMS\Serializer\Tests\Fixtures\BlogPost('FooooooooooooooooooooooBAR', new \JMS\Serializer\Tests\Fixtures\Author('Foo'), new \DateTime, $p);
for ($i = 0; $i < 100; $i++) {
$post->addComment(new \JMS\Serializer\Tests\Fixtures\Comment(new \JMS\Serializer\Tests\Fixtures\Author('foo'), 'foobar'));
}

return $post;
}

$serializer = \JMS\Serializer\SerializerBuilder::create()->build();
$collection = createCollection();
$metrics = array();
$f = function () use ($serializer, $collection, $format) {
$serializer->serialize($collection, $format);
};

// Load all necessary classes into memory.
benchmark($f, 1);

printf('Benchmarking collection for format "%s".' . PHP_EOL, $format);
$metrics['benchmark-collection-' . $format] = benchmark($f, $iterations);

$output = json_encode(array('metrics' => $metrics));

if (isset($_SERVER['argv'][3])) {
file_put_contents($_SERVER['argv'][3], $output);
echo "Done." . PHP_EOL;
} else {
echo $output . PHP_EOL;
}