$blueprint = array('t:' => 'target array to benchmark', 'm:' => 'type of benchmark to perform against the target', 'i:' => 'number of total iterations for the test', 'h' => 'outputs this helpful message'); $options = getopt(implode(null, array_keys($blueprint))); if ($blueprint) { if (isset($options['h'])) { foreach ($blueprint as $option => $description) { $option = str_replace(':', null, $option); if (!isset($options[$option])) { print "Option -" . $option . ": " . $description . "\n"; } } exit(0); } foreach ($blueprint as $option => $description) { if (strpos($option, ':') == false) { continue; } $option = str_replace(':', null, $option); if (!isset($options[$option])) { print "Option -" . $option . " is required, see -h for more information.\n"; exit(0); } } } try { $benchmarker = Factory::instance($options['t']); $benchmarker->setIterations($options['i']); $benchmarker->test($options['m']); } catch (Exception $exception) { print $exception->getMessage(); exit(1); }
use Benchmarker\Factory; try { // Retrieve passed parameters $client = isset($_GET['client']) ? $_GET['client'] : false; $test = isset($_GET['test']) ? $_GET['test'] : false; $serializer = isset($_GET['serializer']) ? $_GET['serializer'] : Factory::SERIALIZER_PHP; // Handle multiple tests passed with : delimiter if ($test) { if (strpos($test, ':') !== false) { $strings = explode(':', $test); if ($strings) { $test = array(); foreach ($strings as $string) { $test[] = $string; } } } } // Initialize test scope and attempt to run requested tests $benchmarker = Factory::instance($client, $serializer); if ($test == 'all') { $benchmarker->all(); } else { $benchmarker->test($test); } } catch (Exception $exception) { header('HTTP/1.1 500 Internal Server Error'); echo $exception->getMessage() . '<br>'; echo $exception->getFile() . ': ' . $exception->getLine(); exit(1); }