Support for larger size codes (such as SNOMED US Extension codes)
[openemr.git] / gacl / test_suite / random_acl_check.php
blob2b3f60a62d71ae4357ae622f390999c924ebfcc8
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <html>
3 <head>
4 <title>Random ACL Check</title>
5 </head>
6 <body>
7 <pre>
8 <?php
10 set_time_limit (6000);
12 /*! function
13 get time accurate to the nearest microsecond, used for script timing
14 !*/
15 function getmicrotime ()
17 list ($usec, $sec) = explode (' ', microtime ());
18 return (float)$usec + (float)$sec;
21 /*! function
22 a better array_rand, this one actualluy works on windows
23 !*/
24 function array_mt_rand ($array, $items)
26 $keys = array_keys ($array);
27 $max = count ($keys) - 1;
29 if ( $items == 1 )
31 return $keys[mt_rand (0, $max)];
34 $return = array ();
36 for ( $i = 1; $i <= $items; $i++ )
38 $return[] = $keys[mt_rand (0, $max)];
41 return $return;
44 /*! function
45 grab random objects from the database
46 !*/
47 function random_objects ($type, $limit = NULL)
49 $sql = 'SELECT id, section_value, value FROM ' . $GLOBALS['gacl_api']->_db_table_prefix . $type . ' ORDER BY RAND()';
51 if ( is_scalar ($limit) )
53 $rs = $GLOBALS['gacl_api']->db->SelectLimit ($sql,$limit);
55 else
57 $rs = $GLOBALS['gacl_api']->db->Execute ($sql);
60 if ( !is_object ($rs) )
62 return FALSE;
65 $retarr = array ();
67 while ( $row = $rs->FetchRow () )
69 $retarr[$row[0]] = array (
70 $row[1],
71 $row[2]
75 return $retarr;
78 // require gacl
79 require_once (dirname (__FILE__) . '/../admin/gacl_admin.inc.php');
82 * Let's get ready to RUMBLE!!!
84 $scale = 100;
86 echo '<b>Random ACL Check</b>' . "\n";
87 echo ' Scale: ' . $scale . "\n\n";
89 $overall_start = getmicrotime ();
91 mt_srand ((double)microtime () *10000);
93 echo "<b>Generating Test Data Set</b>\n";
94 flush ();
96 $start_time = getmicrotime ();
98 $start = 1;
99 $max = 5 * $scale;
100 // $max = 1;
102 $check = array ();
104 $aco = random_objects ('aco', $max);
105 $aro = random_objects ('aro', $max);
106 $axo = random_objects ('axo', $max);
108 for ( $i = $start; $i <= $max; $i++ )
110 $rand_aco_id = array_mt_rand ($aco, 1);
111 $rand_aro_id = array_mt_rand ($aro, 1);
112 $rand_axo_id = array_mt_rand ($axo, 1);
114 // echo ' Rand ACO: '. $rand_aco_id .' ARO: '. $rand_aro_id . ' AXO: ' . $rand_axo_id . "\n";
116 $check[$i] = array (
117 'aco' => $aco[$rand_aco_id],
118 'aro' => $aro[$rand_aro_id],
119 'axo' => $axo[$rand_axo_id]
123 $elapsed = getmicrotime () - $start_time;
125 echo "Done\n\n";
126 echo ' Count: ' . $max . "\n";
127 echo ' Time: ' . $elapsed . " s\n";
128 echo ' Average: ' . $elapsed/$max . " s\n\n";
130 echo "<b>Testing...</b>\n";
131 flush ();
133 $best = 99999;
134 $worst = 0;
135 $total = 0;
137 $allowed = 0;
138 $denied = 0;
140 $allowed_time = 0;
141 $denied_time = 0;
143 foreach ( $check as $i => $data )
145 echo ' Trying: ACO Section: '. $data['aco'][0] .' Value: '. $data['aco'][1] .' ARO Section: '. $data['aro'][0] .' Value: '. $data['aro'][1] . ' ARO Section: '. $data['axo'][0] .' Value: '. $data['axo'][1] . "\n";
147 $check_start = getmicrotime ();
149 $allow = $gacl_api->acl_check ($data['aco'][0],$data['aco'][1],$data['aro'][0],$data['aro'][1],$data['axo'][0],$data['axo'][1]);
151 $check_time = getmicrotime () - $check_start;
153 if ( $allow ) {
154 echo '<font color="#00ff00"> ' . $i . ". Access Granted</font>";
155 $allowed++;
156 $allowed_time += $check_time;
157 } else {
158 echo '<font color="#ff0000"> ' . $i . ". Access Denied</font>";
159 $denied++;
160 $denied_time += $check_time;
163 echo ' - ' . $check_time . " s\n";
165 $best = min ($best, $check_time);
166 $worst = max ($worst, $check_time);
167 $total = $total + $check_time;
170 echo "Done\n";
171 echo ' Count: ' . $max . "\n";
172 echo ' Total: ' . $total . " s\n";
173 echo ' Average: ' . $total/$max . " s\n\n";
175 echo ' Allowed: ' . $allowed . "\n";
176 echo ' Total: ' . $allowed_time . " s\n";
177 echo ' Average: ' . $allowed_time/$allowed . " s\n\n";
179 echo ' Denied: ' . $denied . "\n";
180 echo ' Total: ' . $denied_time . " s\n";
181 echo ' Average: ' . $denied_time/$denied . " s\n\n";
183 echo ' Best: ' . $best . " s\n";
184 echo ' Worst: ' . $worst . " s\n\n";
186 // print_r ($gacl_api->db);
189 $elapsed = getmicrotime () - $overall_start;
191 echo '<b>All Finished</b>' . "\n";
192 echo ' Total Time: ' . $elapsed . " s\n";
195 * end of script
199 </pre>
200 </body>
201 </html>