|
@@ -24,7 +24,7 @@ class BenchController extends Controller
|
|
|
public function dbAction(Request $request)
|
|
|
{
|
|
|
$queries = $request->query->getInt('queries', 1);
|
|
|
- $queries = is_numeric($queries) ? min(max($queries, 1), 500) : 1;
|
|
|
+ $queries = min(max($queries, 1), 500);
|
|
|
|
|
|
// possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
|
|
|
$worlds = array();
|
|
@@ -45,7 +45,7 @@ class BenchController extends Controller
|
|
|
public function dbRawAction(Request $request)
|
|
|
{
|
|
|
$queries = $request->query->getInt('queries', 1);
|
|
|
- $queries = is_numeric($queries) ? min(max($queries, 1), 500) : 1;
|
|
|
+ $queries = min(max($queries, 1), 500);
|
|
|
|
|
|
// possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
|
|
|
$worlds = array();
|
|
@@ -55,7 +55,7 @@ class BenchController extends Controller
|
|
|
$worlds[] = $conn->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
|
|
|
}
|
|
|
|
|
|
- if ($queries == 1) {
|
|
|
+ if ($queries == 1 && !$request->query->has('queries')) {
|
|
|
$worlds = $worlds[0];
|
|
|
}
|
|
|
|
|
@@ -76,8 +76,7 @@ class BenchController extends Controller
|
|
|
$world = $repo->find(mt_rand(1, 10000));
|
|
|
$random_number = mt_rand(1, 10000);
|
|
|
$world->setRandomNumber($random_number);
|
|
|
- $em->persist($world);
|
|
|
- $worlds[] = $world;
|
|
|
+ $worlds[] = $world;
|
|
|
}
|
|
|
|
|
|
$em->flush();
|
|
@@ -96,7 +95,7 @@ class BenchController extends Controller
|
|
|
$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);
|
|
|
+ $worlds[] = array('id' => $id, 'randomNumber' => $random_number);
|
|
|
}
|
|
|
|
|
|
return new JsonResponse($worlds);
|
|
@@ -122,55 +121,4 @@ class BenchController extends Controller
|
|
|
'fortunes' => $fortunes
|
|
|
]);
|
|
|
}
|
|
|
-
|
|
|
- public function fortunesPhpAction()
|
|
|
- {
|
|
|
- $repo = $this->getDoctrine()
|
|
|
- ->getRepository('SkamanderBenchmarkBundle:Fortune');
|
|
|
- $fortunes = $repo->findAll();
|
|
|
-
|
|
|
- $runtimeFortune = new Fortune();
|
|
|
- $runtimeFortune->setId(0)
|
|
|
- ->setMessage('Additional fortune added at request time.');
|
|
|
-
|
|
|
- $fortunes[] = $runtimeFortune;
|
|
|
-
|
|
|
- usort($fortunes, function($left, $right) {
|
|
|
- return strcmp($left->message, $right->message);
|
|
|
- });
|
|
|
-
|
|
|
- return $this->render("SkamanderBenchmarkBundle:Bench:fortunes.html.php", [
|
|
|
- 'fortunes' => $fortunes
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- public function fortunesRawAction()
|
|
|
- {
|
|
|
- $repo = $this->getDoctrine()
|
|
|
- ->getRepository('SkamanderBenchmarkBundle:Fortune');
|
|
|
- $fortunes = $repo->findAll();
|
|
|
-
|
|
|
- $runtimeFortune = new Fortune();
|
|
|
- $runtimeFortune->setId(0)
|
|
|
- ->setMessage('Additional fortune added at request time.');
|
|
|
-
|
|
|
- $fortunes[] = $runtimeFortune;
|
|
|
-
|
|
|
- usort($fortunes, function($left, $right) {
|
|
|
- return strcmp($left->message, $right->message);
|
|
|
- });
|
|
|
-
|
|
|
- // This is not the symfony way to work with templates! It's implemented to show users
|
|
|
- // who don't want to use template engines (like twig), or template sugar (like the slots etc.
|
|
|
- // from symfony 2), because in their opinion already built-in php constructs like foreach +
|
|
|
- // if else + include etc. are enough, that the performance impact should be neglectable, and
|
|
|
- // that the advantages outweigh the disadvantages (performance).
|
|
|
- $title = 'Fortunes';
|
|
|
-
|
|
|
- ob_start();
|
|
|
- include __DIR__ . '/../Resources/views/Bench/raw/content.php';
|
|
|
- $response = ob_get_clean();
|
|
|
-
|
|
|
- return new Response($response);
|
|
|
- }
|
|
|
}
|