leftypol/tools/benchmark.php

58 lines
1.3 KiB
PHP
Raw Normal View History

#!/usr/bin/php
<?php
/*
* benchmark.php - benchmarks thumbnailing methods
*
*/
2012-04-12 02:53:45 +00:00
require dirname(__FILE__) . '/inc/cli.php';
require 'inc/image.php';
// move back to this directory
chdir(dirname(__FILE__));
if(count($argv) != 2)
die("Usage: {$argv[0]} [file]\n");
$file = $argv[1];
$extension = strtolower(substr($file, strrpos($file, '.') + 1));
$out = tempnam($config['tmp'], 'thumb');
$count = 300;
function benchmark($method) {
global $config, $file, $extension, $out, $count;
2012-04-12 02:53:45 +00:00
$config['thumb_method'] = $method;
2012-04-12 02:53:45 +00:00
printf("Method: %s\nThumbnailing %d times... ", $method, $count);
2012-04-12 02:53:45 +00:00
$start = microtime(true);
for($i = 0; $i < $count; $i++) {
$image = new Image($file, $extension);
$thumb = $image->resize(
$config['thumb_ext'] ? $config['thumb_ext'] : $extension,
$config['thumb_width'],
$config['thumb_height']
);
2012-04-12 02:53:45 +00:00
$thumb->to($out);
$thumb->_destroy();
$image->destroy();
}
2012-04-12 02:53:45 +00:00
$end = microtime(true);
2012-04-12 02:53:45 +00:00
printf("Took %.2f seconds (%.2f/second; %.2f ms)\n", $end - $start, $rate = ($count / ($end - $start)), 1000 / $rate);
2012-04-12 02:53:45 +00:00
unlink($out);
}
benchmark('gd');
2013-08-01 07:58:44 +00:00
if (extension_loaded('imagick')) {
benchmark('imagick');
} else {
echo "Imagick extension not loaded... skipping.\n";
}
2012-04-12 02:53:45 +00:00
benchmark('convert');
2013-08-04 10:01:40 +00:00
benchmark('gm');
becnhmark('convert+gifsicle');