This benchmark script checks the speed of each method in any classes it is given. It is a very effective way to compare two different algorithms.
By : jinxidoru
<?php /** * This script runs every method in a set of classes a specified * number of times. The total time taken as well as the average * time per iteration is printed after each test. * * The script is run from the command line with as many arguments * as desired. An attempt is made to require each file given on * the command-line. The last element of the arg list, specifies * the number of iterations to execute for each method. For * example, the following call loads array_funcs.php and iterates * 100 times for each method: * $ php -Cq benchmark.php array_funcs.php 100 * * After loading all of the specified files, any non system class * is instantiated and each of its methods are executed a number * of times equal to the iteration value. When complete, a line * containing the method, total execution time (ms), and average * execution time per call (ms) is displayed. * * Author: Michael Bailey (jinxidoru@byu.net) * Date: June 2004 * License: GPL */
// get an array of the system classes $system_classes = get_declared_classes();
// load the class and file foreach ($_SERVER['argv'] AS $i => $file) @include_once $file;
// get the iteration count $iter = $_SERVER['argv'][count($_SERVER['argv'])-1]; if ($iter < 1) $iter = 1;
// benchmark every class foreach (array_diff(get_declared_classes(),$system_classes) AS $class) { print "\n-= $class =-\n";
// create an instance $inst = new $class();
// test each method foreach (get_class_methods($class) AS $method) { // get start time $start = microtime();
// run method for ($i=0; $i<$iter; $i++) $inst->$method();
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.