Esempio n. 1
0
        foreach ($urls as $label => $url) {
            $size = strlen($label);
            if ($size > $maxSize) {
                $maxSize = $size;
            }
        }
        echo "Repetitions: {$repetition}" . PHP_EOL;
        echo '|_. ' . str_pad('URL', $maxSize - 1) . '|_. Time |_. SQL |' . PHP_EOL;
        foreach ($urls as $label => $url) {
            echo '| ' . str_pad($label, $maxSize) . ' | ';
            $stats = [];
            for ($i = 0; $i < $repetition; ++$i) {
                echo `> logs/all.log`;
                $time = trim(`{ time -p wget -q -O "/dev/null" "{$url}"; } 2>&1`);
                preg_match('/\\d+(.\\d+)/', $time, $m);
                $stats['time'][] = $m[0];
                $stats['sql'][] = trim(`grep -cE "SELECT .*" logs/all.log`);
            }
            echo str_pad($this->average($stats['time']), 6, ' ', STR_PAD_LEFT) . ' | ';
            echo str_pad($this->average($stats['sql']), 5, ' ', STR_PAD_LEFT) . ' |';
            echo PHP_EOL;
        }
    }
}
$benchmark = new benchmark();
$repetition = @$argv[1] ?: 1;
if ($repetition === 'url') {
    var_export($benchmark->getUrls());
} else {
    $benchmark->run((int) $repetition);
}
Esempio n. 2
0
            }
            $this->_maxTagLength = $len;
        }
        return $this->_maxTagLength;
    }
    /**
     * Return the usage help.
     *
     * @return string
     */
    public function usageHelp()
    {
        return <<<USAGE
This scrit initialize all cache tag symlinks.
The script needs read/write permissions to access the magento cache files.

Usage:  php -f app/code/local/Netzarbeiter/Cache/shell/benchmark.php -- [options]

    --init <num> Clear existing cache records and create <num> entries
    --tag <num>  If init was used, specify the number of tags to create (default to 30)
\t--min <num>  If init was used, the min number of tags to use for each record (default 5)
\t--max <num>  If init was used, the max number of tags to use for each record (default min +5)
\t-v           Display statistics for every cache tag
\t--help       This help

USAGE;
    }
}
$init = new benchmark();
$init->run();
Esempio n. 3
0
            if ($i == -1) {
            } elseif ($i == -2) {
            } else {
                if ($i == -3) {
                }
            }
        }
        return number_format(microtime(true) - $time_start, 3);
    }
    public static function run($echo = true)
    {
        $total = 0;
        $server = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '?') . '@' . (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '?');
        $methods = get_class_methods('benchmark');
        $line = str_pad("-", 38, "-");
        $return = "<pre>{$line}\n|" . str_pad("PHP BENCHMARK SCRIPT", 36, " ", STR_PAD_BOTH) . "|\n{$line}\nStart : " . date("Y-m-d H:i:s") . "\nServer : {$server}\nPHP version : " . PHP_VERSION . "\nPlatform : " . PHP_OS . "\n{$line}\n";
        foreach ($methods as $method) {
            if (preg_match('/^test_/', $method)) {
                $total += $result = self::$method();
                $return .= str_pad($method, 25) . " : " . $result . " sec.\n";
            }
        }
        $return .= str_pad("-", 38, "-") . "\n" . str_pad("Total time:", 25) . " : " . $total . " sec.</pre>";
        if ($echo) {
            echo $return;
        }
        return $return;
    }
}
benchmark::run();