BenchController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Skamander\BenchmarkBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. class BenchController extends Controller
  8. {
  9. /**
  10. * @Route("/json", name="_json")
  11. */
  12. public function jsonAction()
  13. {
  14. return new JsonResponse(array('message' => 'Hello World!'));
  15. }
  16. /**
  17. * @Route("/db", name="_db")
  18. *
  19. * Used db?queries={queries} instead of db/{queries} to align the test with most of the other tests
  20. */
  21. public function dbAction(Request $request)
  22. {
  23. $queries = $request->query->getInt('queries', 1);
  24. // possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
  25. $worlds = array();
  26. $repo = $this->getDoctrine()
  27. ->getRepository('SkamanderBenchmarkBundle:World');
  28. for($i = 0; $i < $queries; ++$i) {
  29. $worlds[] = $repo->find(mt_rand(1, 10000));
  30. }
  31. return new JsonResponse($worlds);
  32. }
  33. }