improve scoring to store to presubmitted localhost, fix style and
[ViQa-Kissu.git] / tools / benchmark.php
blobed7c200d808c9d403f19fdf0a4d612689f46611d
1 #!/usr/bin/php
2 <?php
3 /*
4 * benchmark.php - benchmarks thumbnailing methods
6 */
8 require dirname(__FILE__) . '/inc/cli.php';
9 require 'inc/image.php';
11 // move back to this directory
12 chdir(dirname(__FILE__));
14 if(count($argv) != 2)
15 die("Usage: {$argv[0]} [file]\n");
17 $file = $argv[1];
18 $extension = strtolower(substr($file, strrpos($file, '.') + 1));
19 $out = tempnam($config['tmp'], 'thumb');
20 $count = 300;
22 function benchmark($method) {
23 global $config, $file, $extension, $out, $count;
25 $config['thumb_method'] = $method;
27 printf("Method: %s\nThumbnailing %d times... ", $method, $count);
29 $start = microtime(true);
30 for($i = 0; $i < $count; $i++) {
31 $image = new Image($file, $extension);
32 $thumb = $image->resize(
33 $config['thumb_ext'] ? $config['thumb_ext'] : $extension,
34 $config['thumb_width'],
35 $config['thumb_height']
38 $thumb->to($out);
39 $thumb->_destroy();
40 $image->destroy();
42 $end = microtime(true);
44 printf("Took %.2f seconds (%.2f/second; %.2f ms)\n", $end - $start, $rate = ($count / ($end - $start)), 1000 / $rate);
46 unlink($out);
49 benchmark('gd');
50 if (extension_loaded('imagick')) {
51 benchmark('imagick');
52 } else {
53 echo "Imagick extension not loaded... skipping.\n";
55 benchmark('convert');
56 benchmark('gm');
57 becnhmark('convert+gifsicle');