1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#!/usr/bin/php
<?php
/*
* benchmark.php - benchmarks thumbnailing methods
*
*/
require __DIR__ . '/inc/cli.php';
require 'inc/image.php';
// move back to this directory
chdir(__DIR__);
if((is_countable($argv) ? count($argv) : 0) != 2)
die("Usage: {$argv[0]} [file]\n");
$file = $argv[1];
$extension = strtolower(substr((string) $file, strrpos((string) $file, '.') + 1));
$out = tempnam($config['tmp'], 'thumb');
$count = 300;
function benchmark($method) {
global $config, $file, $extension, $out, $count;
$config['thumb_method'] = $method;
printf("Method: %s\nThumbnailing %d times... ", $method, $count);
$start = microtime(true);
for($i = 0; $i < $count; $i++) {
$image = new Image($file, $extension);
$thumb = $image->resize(
$config['thumb_ext'] ?: $extension,
$config['thumb_width'],
$config['thumb_height']
);
$thumb->to($out);
$thumb->_destroy();
$image->destroy();
}
$end = microtime(true);
printf("Took %.2f seconds (%.2f/second; %.2f ms)\n", $end - $start, $rate = ($count / ($end - $start)), 1000 / $rate);
unlink($out);
}
benchmark('gd');
if (extension_loaded('imagick')) {
benchmark('imagick');
} else {
echo "Imagick extension not loaded... skipping.\n";
}
benchmark('convert');
benchmark('gm');
benchmark('convert+gifsicle');
|