Browse Source

additional test fixes

ikkez 11 years ago
parent
commit
b2302e1d9f
3 changed files with 63 additions and 31 deletions
  1. 2 1
      php-fatfree/benchmark_config
  2. 58 27
      php-fatfree/index.php
  3. 3 3
      php-fatfree/setup.py

+ 2 - 1
php-fatfree/benchmark_config

@@ -7,6 +7,7 @@
       "plaintext_url": "/plaintext",
       "plaintext_url": "/plaintext",
       "db_url": "/db-orm",
       "db_url": "/db-orm",
       "query_url": "/db-orm/",
       "query_url": "/db-orm/",
+      "update_url": "/update-orm/",
       "port": 8080,
       "port": 8080,
       "approach": "Realistic",
       "approach": "Realistic",
       "classification": "Fullstack",
       "classification": "Fullstack",
@@ -27,7 +28,7 @@
       "db_url": "/db",
       "db_url": "/db",
       "query_url": "/db/",
       "query_url": "/db/",
       "fortune_url": "/fortune",
       "fortune_url": "/fortune",
-      "update_url": "/updateraw",
+      "update_url": "/update-raw/",
       "port": 8080,
       "port": 8080,
       "approach": "Realistic",
       "approach": "Realistic",
       "classification": "Fullstack",
       "classification": "Fullstack",

+ 58 - 27
php-fatfree/index.php

@@ -8,58 +8,69 @@ $f3->set('UI','ui/');
 
 
 $f3->set('DBS',array('mysql:host=localhost;port=3306;dbname=hello_world','benchmarkdbuser','benchmarkdbpass'));
 $f3->set('DBS',array('mysql:host=localhost;port=3306;dbname=hello_world','benchmarkdbuser','benchmarkdbpass'));
 
 
-// https://github.com/TechEmpower/FrameworkBenchmarks#json-response
+// http: //www.techempower.com/benchmarks/#section=code
+
+// JSON test
 $f3->route('GET /json',function($f3) {
 $f3->route('GET /json',function($f3) {
     /** @var Base $f3 */
     /** @var Base $f3 */
     header("Content-type: application/json");
     header("Content-type: application/json");
-    echo json_encode(array('message' => 'Hello World!'));
+    echo json_encode(array('message' => 'Hello, World!'));
 });
 });
 
 
 
 
-// https://github.com/TechEmpower/FrameworkBenchmarks#database-single-query
-// https://github.com/TechEmpower/FrameworkBenchmarks#database-multiple-queries
+// DB RAW test
 $f3->route(
 $f3->route(
     array(
     array(
-        'GET /db',
-        'GET /db/@queries',
+        'GET /db',                  // database-single-query
+        'GET /db/@queries',         // database-multiple-queries
     ),
     ),
     function ($f3,$params) {
     function ($f3,$params) {
-    /** @var Base $f3 */
-        $params += array('queries' => 1); //default value
+        /** @var Base $f3 */
+        $single = !isset($params['queries']);
+        if ($single)
+            $queries = 1;
+        else {
+            $queries = (int) $params['queries'];
+            $queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
+        }
         $dbc = $f3->get('DBS');
         $dbc = $f3->get('DBS');
         $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
         $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
         $result = array();
         $result = array();
-        for ($i = 0; $i < $params['queries']; ++$i) {
+        for ($i = 0; $i < $queries; $i++) {
             $id = mt_rand(1, 10000);
             $id = mt_rand(1, 10000);
             $result[] = $db->exec('SELECT randomNumber FROM World WHERE id = ?',$id,0,false);
             $result[] = $db->exec('SELECT randomNumber FROM World WHERE id = ?',$id,0,false);
         }
         }
         header("Content-type: application/json");
         header("Content-type: application/json");
-        echo json_encode($result);
+        echo json_encode($single ? $result[0] : $result);
     }
     }
 );
 );
 
 
-// https://github.com/TechEmpower/FrameworkBenchmarks#database-single-query
-// https://github.com/TechEmpower/FrameworkBenchmarks#database-multiple-queries
+// DB ORM test
 $f3->route(
 $f3->route(
     array(
     array(
-         'GET /db-orm',
-         'GET /db-orm/@queries',
+         'GET /db-orm',             // database-single-query
+         'GET /db-orm/@queries',    // database-multiple-queries
     ),
     ),
     function ($f3, $params) {
     function ($f3, $params) {
         /** @var Base $f3 */
         /** @var Base $f3 */
-        $params += array('queries' => 1); //default value
+        $single = !isset($params['queries']);
+        if ($single)
+            $queries = 1;
+        else {
+            $queries = (int) $params['queries'];
+            $queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
+        }
         $dbc = $f3->get('DBS');
         $dbc = $f3->get('DBS');
         $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
         $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
         $mapper = new \DB\SQL\Mapper($db,'World');
         $mapper = new \DB\SQL\Mapper($db,'World');
         $result = array();
         $result = array();
-        for ($i = 0; $i < $params['queries']; ++$i) {
+        for ($i = 0; $i < $queries; $i++) {
             $id = mt_rand(1, 10000);
             $id = mt_rand(1, 10000);
-            $mapper->load(array('where id = ?',$id));
+            $mapper->load(array('id = ?',$id));
             $result[] = $mapper->cast();
             $result[] = $mapper->cast();
         }
         }
-
         header("Content-type: application/json");
         header("Content-type: application/json");
-        echo json_encode($result);
+        echo json_encode($single ? $result[0] : $result);
     }
     }
 );
 );
 
 
@@ -81,20 +92,17 @@ $f3->route('GET /fortune', function ($f3) {
 });
 });
 
 
 
 
-$f3->route(
-    array(
-         'GET /updateraw',
-         'GET /updateraw/@queries',
-    ),function($f3,$params) {
+$f3->route('GET /update-raw/@queries', function($f3,$params) {
     /** @var Base $f3 */
     /** @var Base $f3 */
-    $params += array('queries' => 1); //default value
+    $queries = (int) $params['queries'];
+    $queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
+
     $dbc = $f3->get('DBS');
     $dbc = $f3->get('DBS');
     $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
     $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
 
 
     $result = array();
     $result = array();
-    for ($i = 0; $i < $params['queries']; ++$i) {
+    for ($i = 0; $i < $queries; $i++) {
         $id = mt_rand(1, 10000);
         $id = mt_rand(1, 10000);
-
         $row = array(
         $row = array(
             'id'=>$id,
             'id'=>$id,
             'randomNumber'=>$db->exec('SELECT randomNumber FROM World WHERE id = ?',$id,0,false)
             'randomNumber'=>$db->exec('SELECT randomNumber FROM World WHERE id = ?',$id,0,false)
@@ -110,4 +118,27 @@ $f3->route(
 
 
 });
 });
 
 
+
+$f3->route('GET /update-orm/@queries', function($f3,$params) {
+    /** @var Base $f3 */
+    $queries = (int) $params['queries'];
+    $queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
+
+    $dbc = $f3->get('DBS');
+    $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
+    $world = new \DB\SQL\Mapper($db,'World');
+
+    $result = array();
+    for ($i = 0; $i < $queries; $i++) {
+        $id = mt_rand(1, 10000);
+        $world->load(array('id = ?', $id));
+        $world->randomNumber = mt_rand(1, 10000);
+        $world->save();
+        $result[] = $world->cast();
+    }
+    header("Content-type: application/json");
+    echo json_encode($result);
+
+});
+
 $f3->run();
 $f3->run();

+ 3 - 3
php-fatfree/setup.py

@@ -7,8 +7,8 @@ from os.path import expanduser
 
 
 home = expanduser("~")
 home = expanduser("~")
 
 
-def start(args):
-  setup_util.replace_text("php-fatfree/index.php", "host=.*;", "host=" + args.database_host + ";")
+def start(args, logfile, errfile):
+  setup_util.replace_text("php-fatfree/index.php", "localhost", ""+ args.database_host +"")
   setup_util.replace_text("php-fatfree/deploy/php", "\".*\/FrameworkBenchmarks", "\"" + home + "/FrameworkBenchmarks")
   setup_util.replace_text("php-fatfree/deploy/php", "\".*\/FrameworkBenchmarks", "\"" + home + "/FrameworkBenchmarks")
   setup_util.replace_text("php-fatfree/deploy/php", "Directory .*\/FrameworkBenchmarks", "Directory " + home + "/FrameworkBenchmarks")
   setup_util.replace_text("php-fatfree/deploy/php", "Directory .*\/FrameworkBenchmarks", "Directory " + home + "/FrameworkBenchmarks")
   setup_util.replace_text("php-fatfree/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
   setup_util.replace_text("php-fatfree/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
@@ -30,7 +30,7 @@ def start(args):
     return 0
     return 0
   except subprocess.CalledProcessError:
   except subprocess.CalledProcessError:
     return 1
     return 1
-def stop():
+def stop(logfile, errfile):
   try:
   try:
     if os.name == 'nt':
     if os.name == 'nt':
       subprocess.check_call('appcmd delete site PHP', shell=True, stderr=errfile, stdout=logfile)
       subprocess.check_call('appcmd delete site PHP', shell=True, stderr=errfile, stdout=logfile)