} return $post; } $serializer = \Kcs\Serializer\SerializerBuilder::create()->setEventDispatcher(new \Symfony\Component\EventDispatcher\EventDispatcher())->build(); $collection = createCollection(); $metrics = []; $f = function ($format) use($serializer, $collection) { $serializer->serialize($collection, $format); }; // Load all necessary classes into memory. $f('array'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(['Format', 'Direction', 'Time']); $progressBar = new \Symfony\Component\Console\Helper\ProgressBar($output, 8); $progressBar->start(); foreach (['array', 'json', 'yml', 'xml'] as $format) { $table->addRow([$format, 'serialize', benchmark($f, $format)]); $progressBar->advance(); } $serialized = ['array' => $serializer->serialize($collection, 'array'), 'json' => $serializer->serialize($collection, 'json'), 'yml' => $serializer->serialize($collection, 'yml'), 'xml' => $serializer->serialize($collection, 'xml')]; $type = new \Kcs\Serializer\Type\Type('array', [\Kcs\Serializer\Type\Type::from(\Kcs\Serializer\Tests\Fixtures\BlogPost::class)]); $d = function ($format) use($serializer, $serialized, $type) { $serializer->deserialize($serialized[$format], $type, $format); }; foreach (['array', 'json', 'yml', 'xml'] as $format) { $table->addRow([$format, 'deserialize', benchmark($d, $format)]); $progressBar->advance(); } $progressBar->finish(); $progressBar->clear(); $table->render();