|
@@ -3,27 +3,18 @@
|
|
|
namespace Skamander\BenchmarkBundle\Controller;
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
use Skamander\BenchmarkBundle\Entity\Fortune;
|
|
|
|
|
|
class BenchController extends Controller
|
|
|
{
|
|
|
- /**
|
|
|
- * @Route("/json", name="_json")
|
|
|
- */
|
|
|
+
|
|
|
public function jsonAction()
|
|
|
{
|
|
|
return new JsonResponse(array('message' => 'Hello World!'));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @Route("/db", name="_db")
|
|
|
- *
|
|
|
- * Used db?queries={queries} instead of db/{queries} to align the test with most of the other tests
|
|
|
- */
|
|
|
public function dbAction(Request $request)
|
|
|
{
|
|
|
$queries = $request->query->getInt('queries', 1);
|
|
@@ -40,10 +31,21 @@ class BenchController extends Controller
|
|
|
return new JsonResponse($worlds);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @Route("/fortunes", name="_fortunes")
|
|
|
- * @Template
|
|
|
- */
|
|
|
+ public function dbRawAction(Request $request)
|
|
|
+ {
|
|
|
+ $queries = $request->query->getInt('queries', 1);
|
|
|
+
|
|
|
+ // possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
|
|
|
+ $worlds = array();
|
|
|
+ $conn = $this->get('database_connection');
|
|
|
+
|
|
|
+ for($i = 0; $i < $queries; ++$i) {
|
|
|
+ $worlds[] = $conn->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return new JsonResponse($worlds);
|
|
|
+ }
|
|
|
+
|
|
|
public function fortunesAction()
|
|
|
{
|
|
|
$repo = $this->getDoctrine()
|
|
@@ -66,6 +68,33 @@ class BenchController extends Controller
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- return ['fortunes' => $fortunes];
|
|
|
+ return $this->render("SkamanderBenchmarkBundle:Bench:fortunes.html.twig", [
|
|
|
+ 'fortunes' => $fortunes
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fortunesRawAction()
|
|
|
+ {
|
|
|
+ $conn = $this->get('database_connection');
|
|
|
+ $fortunes = $conn->fetchAll('SELECT * FROM Fortune');
|
|
|
+
|
|
|
+ $fortunes[] = [
|
|
|
+ 'id' => 0,
|
|
|
+ 'message' => 'Additional fortune added at request time.'
|
|
|
+ ];
|
|
|
+
|
|
|
+ usort($fortunes, function($left, $right) {
|
|
|
+ if ($left['message'] === $right['message']) {
|
|
|
+ return 0;
|
|
|
+ } else if ($left['message'] > $right['message']) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return $this->render("SkamanderBenchmarkBundle:Bench:fortunes.html.php", [
|
|
|
+ 'fortunes' => $fortunes
|
|
|
+ ]);
|
|
|
}
|
|
|
}
|