merge upstream phpxmlrpc
[plcapi.git] / php / phpxmlrpc / extras / benchmark.php
similarity index 91%
rename from php/phpxmlrpc/tests/benchmark.php
rename to php/phpxmlrpc/extras/benchmark.php
index 43cbc42..2f0f55a 100644 (file)
@@ -3,11 +3,13 @@
  * Benchmarking suite for the PHP-XMLRPC lib.
  *
  * @author Gaetano Giunta
- * @copyright (c) 2005-2015 G. Giunta
+ * @copyright (c) 2005-2021 G. Giunta
  * @license code licensed under the BSD License: see file license.txt
  *
- * @todo add a test for response ok in call testing
+ * @todo add a check for response ok in call testing
  * @todo add support for --help option to give users the list of supported parameters
+ * @todo make number of test iterations flexible
+ * @todo add https tests
  **/
 
 use PhpXmlRpc\PhpXmlRpc;
@@ -17,9 +19,10 @@ use PhpXmlRpc\Client;
 use PhpXmlRpc\Response;
 use PhpXmlRpc\Encoder;
 
+/// @todo allow autoloading when the library is installed as dependency
 include_once __DIR__ . '/../vendor/autoload.php';
 
-include __DIR__ . '/parse_args.php';
+include __DIR__ . '/../tests/parse_args.php';
 $args = argParser::getArgs();
 
 function begin_test($test_name, $test_case)
@@ -167,7 +170,7 @@ for ($i = 0; $i < $num_tests; $i++) {
     for ($k = 0; $k < $l; $k++) {
         $val1 = $value->arraymem($k);
         $out = array();
-        while (list($name, $val) = $val1->structeach()) {
+        foreach($val1 as $name => $val) {
             $out[$name] = array();
             $m = $val->arraysize();
             for ($j = 0; $j < $m; $j++) {
@@ -198,21 +201,23 @@ if (function_exists('xmlrpc_decode')) {
 
 if (!$xd) {
 
+    $num_tests = 25;
+
     /// test multicall vs. many calls vs. keep-alives
     $encoder = new Encoder();
     $value = $encoder->encode($data1, array('auto_dates'));
     $req = new Request('interopEchoTests.echoValue', array($value));
     $reqs = array();
-    for ($i = 0; $i < 25; $i++) {
+    for ($i = 0; $i < $num_tests; $i++) {
         $reqs[] = $req;
     }
-    $server = explode(':', $args['LOCALSERVER']);
+    $server = explode(':', $args['HTTPSERVER']);
     if (count($server) > 1) {
-        $srv = $server[1] . '://' . $server[0] . $args['URI'];
-        $c = new Client($args['URI'], $server[0], $server[1]);
+        $srv = $server[1] . '://' . $server[0] . $args['HTTPURI'];
+        $c = new Client($args['HTTPURI'], $server[0], $server[1]);
     } else {
-        $srv = $args['LOCALSERVER'] . $args['URI'];
-        $c = new Client($args['URI'], $args['LOCALSERVER']);
+        $srv = $args['HTTPSERVER'] . $args['HTTPURI'];
+        $c = new Client($args['HTTPURI'], $args['HTTPSERVER']);
     }
     // do not interfere with http compression
     $c->accepted_compression = array();
@@ -225,7 +230,7 @@ if (!$xd) {
     }
     begin_test($testName, 'http 10');
     $response = array();
-    for ($i = 0; $i < 25; $i++) {
+    for ($i = 0; $i < $num_tests; $i++) {
         $resp = $c->send($req);
         $response[] = $resp->value();
     }
@@ -234,7 +239,7 @@ if (!$xd) {
     if (function_exists('curl_init')) {
         begin_test($testName, 'http 11 w. keep-alive');
         $response = array();
-        for ($i = 0; $i < 25; $i++) {
+        for ($i = 0; $i < $num_tests; $i++) {
             $resp = $c->send($req, 10, 'http11');
             $response[] = $resp->value();
         }
@@ -243,7 +248,7 @@ if (!$xd) {
         $c->keepalive = false;
         begin_test($testName, 'http 11');
         $response = array();
-        for ($i = 0; $i < 25; $i++) {
+        for ($i = 0; $i < $num_tests; $i++) {
             $resp = $c->send($req, 10, 'http11');
             $response[] = $resp->value();
         }
@@ -263,7 +268,7 @@ if (!$xd) {
 
         begin_test($testName, 'http 10 w. compression');
         $response = array();
-        for ($i = 0; $i < 25; $i++) {
+        for ($i = 0; $i < $num_tests; $i++) {
             $resp = $c->send($req);
             $response[] = $resp->value();
         }
@@ -272,7 +277,7 @@ if (!$xd) {
         if (function_exists('curl_init')) {
             begin_test($testName, 'http 11 w. keep-alive and compression');
             $response = array();
-            for ($i = 0; $i < 25; $i++) {
+            for ($i = 0; $i < $num_tests; $i++) {
                 $resp = $c->send($req, 10, 'http11');
                 $response[] = $resp->value();
             }
@@ -281,7 +286,7 @@ if (!$xd) {
             $c->keepalive = false;
             begin_test($testName, 'http 11 w. compression');
             $response = array();
-            for ($i = 0; $i < 25; $i++) {
+            for ($i = 0; $i < $num_tests; $i++) {
                 $resp = $c->send($req, 10, 'http11');
                 $response[] = $resp->value();
             }