Quellcode durchsuchen

Separated into single and multiple test function into two different function

Sanjoy Dey vor 10 Jahren
Ursprung
Commit
d627fcc157

+ 26 - 14
frameworks/PHP/cygnite-php-framework/apps/controllers/BenchController.php

@@ -19,22 +19,23 @@ class BenchController extends AbstractBaseController
         echo 'Hello World!';
     }
 
-    public function dbAction($queries)
+    public function dbAction()
     {
         $worlds = $arr = array();
         $world = null;
+        $queries = 1;
 
-        $flag = false;
-        if (is_null($queries)) {
-            $queries = 1;
-            $flag = true;
-        }
-        $queries = intval($queries);
-        if ($queries < 1) {
-            $queries = 1;
-        } elseif ($queries > 500) {
-            $queries = 500;
-        }
+        $worlds = $this->getWorldsInfo($queries);
+        $worlds = $worlds[0];
+
+        header('Content-type: application/json');
+        echo json_encode($worlds);
+    }
+
+    private function getWorldsInfo($queries)
+    {
+        $world = null;
+        $worlds = $arr = array();
 
         for ($i = 0; $i < $queries; ++$i) {
             $world = World::find(mt_rand(1, 10000));
@@ -43,10 +44,21 @@ class BenchController extends AbstractBaseController
             $worlds[] = $arr;
         }
 
-        if ($flag) {
-            $worlds = $worlds[0];
+        return $worlds;
+    }
+
+    public function queriesAction($queries = 1)
+    {
+        $queries = intval($queries);
+        if ($queries < 1 ) {
+            $queries = 1;
+        } elseif ($queries > 500) {
+            $queries = 500;
         }
 
+        $worlds = array();
+        $worlds = $this->getWorldsInfo($queries);
+
         header('Content-type: application/json');
         echo json_encode($worlds);
     }

+ 1 - 1
frameworks/PHP/cygnite-php-framework/benchmark_config.json

@@ -23,7 +23,7 @@
     "raw": {
       "setup_file": "setup",
       "db_url": "/index.php/bench/db",
-      "query_url": "/index.php/bench/db/",
+      "query_url": "/index.php/bench/queries/",
       "fortune_url": "/index.php/bench/fortunes",
       "port": 8080,
       "approach": "Realistic",