AJAX
[ class tree: AJAX ] [ index: AJAX ] [ all elements ]

Source for file test_speed.php

Documentation is available at test_speed.php

  1. <?php
  2. /**
  3.  * Simple speed test using the null serializer, possibly useful in comparing overhead when tested on local host
  4.  *
  5.  *
  6.  * @category   HTML
  7.  * @package    AJAX
  8.  * @author     Joshua Eichorn <josh@bluga.net>
  9.  * @copyright  2005 Joshua Eichorn
  10.  * @license    http://www.opensource.org/licenses/lgpl-license.php  LGPL
  11.  * @version    Release: @package_version@
  12.  * @link       http://pear.php.net/package/HTML_AJAX
  13.  */
  14.     include 'HTML/AJAX.php';
  15.  
  16.     include '../support/test.class.php';
  17.  
  18.  
  19.  
  20.     $ajax = new HTML_AJAX();
  21.     $ajax->serializer = "Null";
  22.     $ajax->unserializer = "Null";
  23.     $ajax->registerClass(new test());
  24.  
  25.     if ($ajax->handleRequest()) {
  26.         die();
  27.     }
  28. ?><html>
  29. <head>
  30.  
  31. <script type='text/javascript' src="../server.php?client=all&stub=all"></script>
  32. </head>
  33. <body>
  34. <script type="text/javascript">
  35. var t = new test();
  36. var t2 = new test({echo_string: function(){ endCall('Async Echo'); totalA(); }});
  37.  
  38. var time1;
  39. var total = 0;
  40. var count = 0;
  41.  
  42. function speedTest() {
  43.  
  44.     document.getElementById('target').innerHTML += "10 Sync Calls<br>";
  45.     for(var i = 0; i < 10; i++) {
  46.         startCall();
  47.         t.echo_string('Test');
  48.         endCall('Sync Echo');
  49.     }
  50.     document.getElementById('target').innerHTML += "Total: "+total+"<br><br><br>";
  51.     total = 0;
  52.  
  53.     document.getElementById('target').innerHTML += "10 Async Calls<br>";
  54.     count = 0;
  55.     for(var i = 0; i < 10; i++) {
  56.         setTimeout("runAsync();",500*i);
  57.     }
  58.     total = 0;
  59.  
  60. }
  61. function totalA() {
  62.     count++;
  63.     if (count == 10) {
  64.         document.getElementById('target').innerHTML += "Total: "+total+"<br>";
  65.     }
  66. }
  67. function runAsync() {
  68.     startCall();
  69.     t2.echo_string('Test');
  70. }
  71. function startCall() {
  72.     time1 = new Date();
  73. }
  74. function endCall(name) {
  75.     var time = 0;
  76.  
  77.     var time2 = new Date();
  78.  
  79.     time = time2.getTime() - time1.getTime();
  80.     total += time;
  81.     
  82.     document.getElementById('target').innerHTML += name+":"+time+"<br>";
  83. }
  84.  
  85.  
  86. </script>
  87. <a href="javascript:speedTest()">Start Speed Test</a>
  88. <div id="target">
  89. </div>
  90. </body>
  91. </html>

Documentation generated on Sat, 05 May 2007 18:00:25 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.