/extension/tests/xhprof_005.phpt

http://github.com/preinheimer/xhprof · Unknown · 82 lines · 67 code · 15 blank · 0 comment · 0 complexity · e8f1ad99812846249faa0e5d395c7dcc MD5 · raw file

  1. --TEST--
  2. XHPRrof: Timer Tests
  3. Author: Kannan
  4. --FILE--
  5. <?php
  6. //
  7. // Some coarse grained sanity tests for the time just
  8. // to make sure profiler's timer implementation isn't
  9. // way off.
  10. // The test allows for a 25% margin of error.
  11. //
  12. include_once dirname(__FILE__).'/common.php';
  13. // sleep 10000 microsecs (10 millisecs)
  14. function sleep_10000_micro() {
  15. usleep(10000);
  16. }
  17. // sleep 20000 microsecs (20 millisecs)
  18. function sleep_20000_micro() {
  19. usleep(20000);
  20. }
  21. // sleep 50000 microsecs (50 millisecs)
  22. function sleep_50000_micro() {
  23. usleep(50000);
  24. }
  25. function invoke_all() {
  26. sleep_10000_micro();
  27. sleep_20000_micro();
  28. sleep_50000_micro();
  29. }
  30. xhprof_enable();
  31. invoke_all();
  32. $output = xhprof_disable();
  33. // verify output
  34. function verify($expected, $actual, $description) {
  35. echo "Verifying ${description}...\n";
  36. // 25% tolerance
  37. $range_low = ($expected * 0.75);
  38. $range_high = ($expected * 1.25);
  39. if (($actual < $range_low) ||
  40. ($actual > $range_high)) {
  41. echo "Failed ${description}. Expected: ${expected} microsecs. ".
  42. "Actual: ${actual} microsecs.\n";
  43. } else {
  44. echo "OK: ${description}\n";
  45. }
  46. echo "-------------\n";
  47. }
  48. verify(10000,
  49. $output["sleep_10000_micro==>usleep"]["wt"],
  50. "sleep_10000_micro");
  51. verify(20000,
  52. $output["sleep_20000_micro==>usleep"]["wt"],
  53. "sleep_20000_micro");
  54. verify(50000,
  55. $output["sleep_50000_micro==>usleep"]["wt"],
  56. "sleep_50000_micro");
  57. ?>
  58. --EXPECT--
  59. Verifying sleep_10000_micro...
  60. OK: sleep_10000_micro
  61. -------------
  62. Verifying sleep_20000_micro...
  63. OK: sleep_20000_micro
  64. -------------
  65. Verifying sleep_50000_micro...
  66. OK: sleep_50000_micro
  67. -------------