|
@@ -1,19 +1,22 @@
|
|
<?php
|
|
<?php
|
|
|
|
|
|
-namespace Skamander\BenchmarkBundle\Controller;
|
|
|
|
|
|
+namespace App\Controller;
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
+use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
-use Skamander\BenchmarkBundle\Entity\Fortune;
|
|
|
|
|
|
+use App\Entity\Fortune;
|
|
|
|
+use App\Entity\World;
|
|
|
|
|
|
class BenchController extends Controller
|
|
class BenchController extends Controller
|
|
{
|
|
{
|
|
|
|
+ use ControllerTrait;
|
|
|
|
|
|
public function plaintextAction()
|
|
public function plaintextAction()
|
|
{
|
|
{
|
|
- return new Response("Hello, World!", 200, array('Content-Type' => 'text/plain'));
|
|
|
|
|
|
+ return new Response("Hello, World!", 200, array('Content-Type' => 'text/plain'));
|
|
}
|
|
}
|
|
|
|
|
|
public function jsonAction()
|
|
public function jsonAction()
|
|
@@ -28,11 +31,10 @@ class BenchController extends Controller
|
|
|
|
|
|
// possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
|
|
// possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
|
|
$worlds = array();
|
|
$worlds = array();
|
|
- $repo = $this->getDoctrine()
|
|
|
|
- ->getRepository('SkamanderBenchmarkBundle:World');
|
|
|
|
|
|
+ $repo = $this->getDoctrine()->getRepository(World::class);
|
|
|
|
|
|
for ($i = 0; $i < $queries; ++$i) {
|
|
for ($i = 0; $i < $queries; ++$i) {
|
|
- $worlds[] = $repo->find(mt_rand(1, 10000));
|
|
|
|
|
|
+ $worlds[] = $repo->find(mt_rand(1, 10000));
|
|
}
|
|
}
|
|
|
|
|
|
if ($queries == 1 && !$request->query->has('queries')) {
|
|
if ($queries == 1 && !$request->query->has('queries')) {
|
|
@@ -51,8 +53,8 @@ class BenchController extends Controller
|
|
$worlds = array();
|
|
$worlds = array();
|
|
$conn = $this->get('database_connection');
|
|
$conn = $this->get('database_connection');
|
|
|
|
|
|
- for($i = 0; $i < $queries; ++$i) {
|
|
|
|
- $worlds[] = $conn->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
|
|
|
|
|
|
+ for ($i = 0; $i < $queries; ++$i) {
|
|
|
|
+ $worlds[] = $conn->fetchAssoc('SELECT * FROM world WHERE id = ?', array(mt_rand(1, 10000)));
|
|
}
|
|
}
|
|
|
|
|
|
if ($queries == 1 && !$request->query->has('queries')) {
|
|
if ($queries == 1 && !$request->query->has('queries')) {
|
|
@@ -69,17 +71,17 @@ class BenchController extends Controller
|
|
|
|
|
|
$worlds = array();
|
|
$worlds = array();
|
|
$em = $this->getDoctrine()->getManager();
|
|
$em = $this->getDoctrine()->getManager();
|
|
- $repo = $this->getDoctrine()
|
|
|
|
- ->getRepository('SkamanderBenchmarkBundle:World');
|
|
|
|
|
|
+ $repo = $this->getDoctrine()->getRepository(World::class);
|
|
|
|
|
|
for ($i = 0; $i < $queries; ++$i) {
|
|
for ($i = 0; $i < $queries; ++$i) {
|
|
$world = $repo->find(mt_rand(1, 10000));
|
|
$world = $repo->find(mt_rand(1, 10000));
|
|
- $random_number = mt_rand(1, 10000);
|
|
|
|
- $world->setRandomNumber($random_number);
|
|
|
|
|
|
+ $randomNumber = mt_rand(1, 10000);
|
|
|
|
+ $world->setRandomNumber($randomNumber);
|
|
$worlds[] = $world;
|
|
$worlds[] = $world;
|
|
}
|
|
}
|
|
|
|
|
|
$em->flush();
|
|
$em->flush();
|
|
|
|
+
|
|
return new JsonResponse($worlds);
|
|
return new JsonResponse($worlds);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -91,11 +93,11 @@ class BenchController extends Controller
|
|
$worlds = array();
|
|
$worlds = array();
|
|
$conn = $this->get('database_connection');
|
|
$conn = $this->get('database_connection');
|
|
|
|
|
|
- for($i = 0; $i < $queries; ++$i) {
|
|
|
|
|
|
+ for ($i = 0; $i < $queries; ++$i) {
|
|
$id = mt_rand(1, 10000);
|
|
$id = mt_rand(1, 10000);
|
|
- $random_number = mt_rand(1, 10000);
|
|
|
|
- $conn->executeUpdate('UPDATE World SET randomNumber=? WHERE id=?', array($random_number, $id));
|
|
|
|
- $worlds[] = array('id' => $id, 'randomNumber' => $random_number);
|
|
|
|
|
|
+ $randomNumber = mt_rand(1, 10000);
|
|
|
|
+ $conn->executeUpdate('UPDATE world SET randomNumber=? WHERE id=?', array($randomNumber, $id));
|
|
|
|
+ $worlds[] = array('id' => $id, 'randomNumber' => $randomNumber);
|
|
}
|
|
}
|
|
|
|
|
|
return new JsonResponse($worlds);
|
|
return new JsonResponse($worlds);
|
|
@@ -103,8 +105,7 @@ class BenchController extends Controller
|
|
|
|
|
|
public function fortunesAction()
|
|
public function fortunesAction()
|
|
{
|
|
{
|
|
- $repo = $this->getDoctrine()
|
|
|
|
- ->getRepository('SkamanderBenchmarkBundle:Fortune');
|
|
|
|
|
|
+ $repo = $this->getDoctrine()->getRepository(Fortune::class);
|
|
$fortunes = $repo->findAll();
|
|
$fortunes = $repo->findAll();
|
|
|
|
|
|
$runtimeFortune = new Fortune();
|
|
$runtimeFortune = new Fortune();
|
|
@@ -117,7 +118,7 @@ class BenchController extends Controller
|
|
return strcmp($left->message, $right->message);
|
|
return strcmp($left->message, $right->message);
|
|
});
|
|
});
|
|
|
|
|
|
- return $this->render("SkamanderBenchmarkBundle:Bench:fortunes.html.twig", [
|
|
|
|
|
|
+ return $this->render("bench/fortunes.html.twig", [
|
|
'fortunes' => $fortunes
|
|
'fortunes' => $fortunes
|
|
]);
|
|
]);
|
|
}
|
|
}
|