Browse Source

Delete unnecessary validation (#5052)

in while()
Joan Miquel 6 years ago
parent
commit
e9a3c6857b

+ 3 - 3
frameworks/PHP/kumbiaphp/bench/app/controllers/db_controller.php

@@ -13,11 +13,11 @@ class DbController extends AppController
         echo json_encode(World::byId(mt_rand(1, 10000)));
     }
 
-    public function queries($count = 1)
+    public function query($count = 1)
     {
         $count = min(max($count, 1), 500);
         $worlds = [];
-        for ($i = 0; $i < $count; ++$i) {
+        while ($count--) {
             $worlds[] = World::byId(mt_rand(1, 10000));
         }
         echo json_encode($worlds);
@@ -27,7 +27,7 @@ class DbController extends AppController
     {
         $count = min(max($count, 1), 500);
         $worlds = [];
-        for ($i = 0; $i < $count; ++$i) {
+        while ($count--) {
             $row = World::byId(mt_rand(1, 10000));
             $row->randomNumber = mt_rand(1, 10000);
             $row->update();

+ 3 - 3
frameworks/PHP/kumbiaphp/bench/app/controllers/raw_controller.php

@@ -20,12 +20,12 @@ class RawController extends AppController
         echo json_encode($statement->fetch(PDO::FETCH_ASSOC));
     }
 
-    public function queries($count = 1)
+    public function query($count = 1)
     {
         $count = min(max($count, 1), 500);
         $res = $this->pdo->prepare('SELECT id,randomNumber FROM World WHERE id = ?');
         $worlds = [];
-        for ($i = 0; $i < $count; ++$i) {
+        while ($count--) {
             $res->execute([mt_rand(1, 10000)]);
             $worlds[] = $res->fetch(PDO::FETCH_ASSOC);
         }
@@ -40,7 +40,7 @@ class RawController extends AppController
         $sth = $this->pdo->prepare('SELECT * FROM World WHERE id = ?');
         $updateSth = $this->pdo->prepare('UPDATE World SET randomNumber = ? WHERE id = ?');
         
-        for ($i = 0; $i < $count; ++$i) {
+        while ($count--) {
             $id = mt_rand(1, 10000);
 
             $sth->execute([$id]);

+ 2 - 2
frameworks/PHP/kumbiaphp/benchmark_config.json

@@ -5,7 +5,7 @@
             "plaintext_url": "/",
             "json_url": "/json",
             "db_url": "/db",
-            "query_url": "/db/queries/",
+            "query_url": "/db/query/",
             "fortune_url": "/fortune",
             "update_url": "/db/update/",
             "port": 8080,
@@ -26,7 +26,7 @@
         },
         "raw": {
             "db_url": "/raw",
-            "query_url": "/raw/queries/",
+            "query_url": "/raw/query/",
             "fortune_url": "/raw-fortune",
             "update_url": "/raw/update/",
             "port": 8080,

+ 1 - 1
frameworks/PHP/php/dborm.php

@@ -29,7 +29,7 @@ if ($_GET['queries'] > 1) {
 // Create an array with the response string.
 $arr = [];
 // For each query, store the result set values in the response array
-while (0 < $query_count--) {
+while ($query_count--) {
     // Store result in array.
     $arr[] = World::find_by_id(mt_rand(1, 10000))->to_array();
 }

+ 2 - 2
frameworks/PHP/php/dbquery.php

@@ -10,7 +10,7 @@ $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser',
 // Read number of queries to run from URL parameter
 $query_count = 1;
 if ($_GET['queries'] > 1) {
-  $query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
+  $query_count = min($_GET['queries'], 500);
 }
 
 // Create an array with the response string.
@@ -20,7 +20,7 @@ $arr = [];
 $statement = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id = ?');
 
 // For each query, store the result set values in the response array
-while (0 < $query_count--) {
+while ($query_count--) {
   $statement->execute( [mt_rand(1, 10000)] );
   
   // Store result in array.

+ 1 - 1
frameworks/PHP/php/eloquent/db-eloquent.php

@@ -17,7 +17,7 @@ if ($_GET['queries'] > 1) {
 // Create an array with the response string.
 $arr = [];
 // For each query, store the result set values in the response array
-while (0 < $query_count--) {
+while ($query_count--) {
     // Store result in array.
     $arr[] = World::find(mt_rand(1, 10000));
 }

+ 1 - 1
frameworks/PHP/php/eloquent/db-laravel-query-builder.php

@@ -21,7 +21,7 @@ if ($_GET['queries'] > 1) {
 // Create an array with the response string.
 $arr = [];
 // For each query, store the result set values in the response array
-while (0 < $query_count--) {
+while ($query_count--) {
     // Store result in array.
     $arr[] = Capsule::table('World')->where('id', mt_rand(1, 10000))->get()->first();
 }

+ 1 - 1
frameworks/PHP/php/eloquent/update-eloquent.php

@@ -12,7 +12,7 @@ if (isset($_GET['queries']) && $_GET['queries'] > 0) {
 $arr = array();
 
 // For each query, store the result set values in the response array
-while (0 < $query_count--) {
+while ($query_count--) {
   $id = mt_rand(1, 10000);
   $randomNumber = mt_rand(1, 10000);
 

+ 2 - 2
frameworks/PHP/php/updateraw.php

@@ -10,7 +10,7 @@ $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser',
 // Read number of queries to run from URL parameter
 $query_count = 1;
 if ($_GET['queries'] > 1) {
-  $query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
+  $query_count = min($_GET['queries'], 500);
 }
 
 // Create an array with the response string.
@@ -21,7 +21,7 @@ $statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id = ?');
 $updateStatement = $pdo->prepare('UPDATE World SET randomNumber = ? WHERE id = ?');
 
 // For each query, store the result set values in the response array
-while (0 < $query_count--) {
+while ($query_count--) {
     $id = mt_rand(1, 10000);
     $statement->execute([$id]);