Browse Source

adds plaintext and update tests to yaf

Keith Newman 9 years ago
parent
commit
71c0b3193d

+ 37 - 0
frameworks/PHP/yaf/app/modules/Bench/controllers/Raw.php

@@ -5,6 +5,12 @@ use Yaf\Controller_Abstract as AbstractController;
 class RawController extends AbstractController
 {
 
+    public function plaintextAction ()
+    {
+      header('Content-Type: text/plain');
+      die("Hello, World!");
+    }
+
     public function jsonAction ()
     {
         header('Content-type: application/json');
@@ -43,6 +49,37 @@ class RawController extends AbstractController
         die(json_encode($arr));
     }
 
+    public function updatesAction ()
+    {
+      $dbh = DatabaseManager::getInstance()->getConnection();
+
+      $query_count = (int) $this->getRequest()->get('queries', 1);
+
+      if (0 >= $query_count) {
+          $query_count = 1;
+      } elseif (500 < $query_count) {
+          $query_count = 500;
+      }
+
+      $arr = array();
+      $id = mt_rand(1, 10000);
+      $random_number = mt_rand(1, 10000);
+
+      $statement = $dbh->prepare('UPDATE `World` SET `randomNumber` = :random_number WHERE `id` = :id');
+      $statement->bindParam(':id', $id, \PDO::PARAM_INT);
+      $statement->bindParam(':random_number', $random_number, \PDO::PARAM_INT);
+
+      while (0 < $query_count--) {
+          $statement->execute();
+          $arr[] = array('id' => $id, 'randomNumber' => $random_number);
+          $random_number = mt_rand(1, 10000);
+          $id = mt_rand(1, 10000);
+      }
+
+      header('Content-type: application/json');
+      die(json_encode($arr));
+    }
+
     public function fortunesAction ()
     {
         $view = $this->getView();

+ 2 - 0
frameworks/PHP/yaf/benchmark_config.json

@@ -3,8 +3,10 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/bench/raw/plaintext",
       "json_url": "/bench/raw/json",
       "db_url": "/bench/raw/db",
+      "update_url": "/bench/raw/updates?queries=",
       "query_url": "/bench/raw/db?queries=",
       "fortune_url": "/bench/raw/fortunes",
       "port": 8080,