PageRenderTime 16ms CodeModel.GetById 14ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

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