1 <!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4 <title
>Random ACL Check
</title
>
10 set_time_limit (6000);
13 get time accurate to the nearest microsecond, used for script timing
15 function getmicrotime ()
17 list ($usec, $sec) = explode (' ', microtime ());
18 return (float)$usec +
(float)$sec;
22 a better array_rand, this one actualluy works on windows
24 function array_mt_rand ($array, $items)
26 $keys = array_keys ($array);
27 $max = count ($keys) - 1;
31 return $keys[mt_rand (0, $max)];
36 for ( $i = 1; $i <= $items; $i++
)
38 $return[] = $keys[mt_rand (0, $max)];
45 grab random objects from the database
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);
57 $rs = $GLOBALS['gacl_api']->db
->Execute ($sql);
60 if ( !is_object ($rs) )
67 while ( $row = $rs->FetchRow () )
69 $retarr[$row[0]] = array (
79 require_once (dirname (__FILE__
) . '/../admin/gacl_admin.inc.php');
82 * Let's get ready to RUMBLE!!!
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";
96 $start_time = getmicrotime ();
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";
117 'aco' => $aco[$rand_aco_id],
118 'aro' => $aro[$rand_aro_id],
119 'axo' => $axo[$rand_axo_id]
123 $elapsed = getmicrotime () - $start_time;
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";
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;
154 echo '<font color="#00ff00"> ' . $i . ". Access Granted</font>";
156 $allowed_time +
= $check_time;
158 echo '<font color="#ff0000"> ' . $i . ". Access Denied</font>";
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;
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";