diff options
| author | Michael Save <savetheinternet@tinyboard.org> | 2012-03-31 10:59:20 +1100 |
|---|---|---|
| committer | Michael Save <savetheinternet@tinyboard.org> | 2012-03-31 10:59:20 +1100 |
| commit | fef9a3ca82144348924852f68aee35ff4bf6ca25 (patch) | |
| tree | 2eb7dd277177fcbd572884d15ed3ce100aa61c7c /tools/benchmark.php | |
| parent | 52443d3da98e992953d8214b7848350f70d02336 (diff) | |
| parent | 2df1ebd88c266d984cbaa6c26917c2ea89c2ae0e (diff) | |
Merge branch 'master' of github.com:savetheinternet/Tinyboard-Tools into tools
Conflicts:
README.md
Diffstat (limited to 'tools/benchmark.php')
| -rwxr-xr-x | tools/benchmark.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/benchmark.php b/tools/benchmark.php new file mode 100755 index 00000000..60aba638 --- /dev/null +++ b/tools/benchmark.php @@ -0,0 +1,52 @@ +#!/usr/bin/php +<?php +/* + * benchmark.php - benchmarks thumbnailing methods + * + */ + + 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; + + $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'] ? $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'); + benchmark('imagick'); + benchmark('convert'); + |
