dmitry          Thu Oct 25 05:39:06 2007 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src    NEWS 
    /php-src/sapi/cgi   cgi_main.c 
  Log:
  Added CGI SAPI -T option, to measure execution time of script repeated 
several times.
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.32&r2=1.2027.2.547.2.965.2.33&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.32 
php-src/NEWS:1.2027.2.547.2.965.2.33
--- php-src/NEWS:1.2027.2.547.2.965.2.32        Tue Oct 23 09:55:10 2007
+++ php-src/NEWS        Thu Oct 25 05:39:05 2007
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 20??, PHP 5.3.0
+- Added CGI SAPI -T option, to measure execution time of script repeated
+  several times. (Dmitry)
 - Added icon format support to getimagesize(). (Scott)
 - Added LDAP_OPT_NETWORK_TIMEOUT option for ldap_set_option() to allow
   setting network timeout (FR #42837). (Jani)
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.50.2.4&r2=1.267.2.15.2.50.2.5&diff_format=u
Index: php-src/sapi/cgi/cgi_main.c
diff -u php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.4 
php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.5
--- php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.4     Mon Oct  1 12:40:54 2007
+++ php-src/sapi/cgi/cgi_main.c Thu Oct 25 05:39:06 2007
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.4 2007/10/01 12:40:54 jani Exp $ */
+/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.5 2007/10/25 05:39:06 dmitry Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -137,6 +137,7 @@
        {'?', 0, "usage"},/* help alias (both '?' and 'usage') */
        {'v', 0, "version"},
        {'z', 1, "zend-extension"},
+       {'T', 1, "timing"},
        {'-', 0, NULL} /* end of args */
 };
 
@@ -758,7 +759,8 @@
                                "  -s               Display colour syntax 
highlighted source.\n"
                                "  -v               Version number\n"
                                "  -w               Display source with 
stripped comments and whitespace.\n"
-                               "  -z <file>        Load Zend extension 
<file>.\n",
+                               "  -z <file>        Load Zend extension 
<file>.\n"
+                          "  -T <count>       Measure execution time of script 
repeated <count> times.\n",
                                prog, prog);
 }
 /* }}} */
@@ -1257,6 +1259,9 @@
        char *bindpath = NULL;
        int fcgi_fd = 0;
        fcgi_request request;
+       int repeats = 1;
+       int benchmark = 0;
+       struct timeval start, end;
 #ifndef PHP_WIN32
        int status = 0;
 #endif
@@ -1533,6 +1538,11 @@
        zend_first_try {
                while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, 
&php_optind, 1, 2)) != -1) {
                        switch (c) {
+                               case 'T':
+                               benchmark = 1;
+                                       repeats = atoi(php_optarg);
+                                       gettimeofday(&start, NULL);
+                                       break;
                                case 'h':
                                case '?':
                                        fcgi_shutdown();
@@ -1907,8 +1917,18 @@
                                }
                        }
 
-                       if (!fastcgi)
+                       if (!fastcgi) {
+                               if (benchmark) {
+                                       repeats--;
+                                       if (repeats > 0) {
+                                               script_file = NULL;
+                                               php_optind = orig_optind;
+                                               php_optarg = orig_optarg;
+                                               continue;
+                                       }
+                               }
                                break;
+                       }
 
                        /* only fastcgi will get here */
                        requests++;
@@ -1938,6 +1958,21 @@
        } zend_end_try();
 
 out:
+       if (benchmark) {
+               int sec;
+               int usec;
+
+               gettimeofday(&end, NULL);
+               sec = (int)(end.tv_sec - start.tv_sec);
+               if (end.tv_usec >= start.tv_usec) {
+                       usec = (int)(end.tv_usec - start.tv_usec);
+               } else {
+                       sec -= 1;
+                       usec = (int)(end.tv_usec + 1000000 - start.tv_usec);
+               }
+               fprintf(stderr, "\nElapsed time: %d.%06d sec\n", sec, usec);
+       }
+
        SG(server_context) = NULL;
        php_module_shutdown(TSRMLS_C);
        sapi_shutdown();

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to