summaryrefslogtreecommitdiff
path: root/tools/benchmark.php
diff options
context:
space:
mode:
authorCzterooki <czterooki1337@gmail.com>2013-07-20 00:19:08 -0400
committerCzterooki <czterooki1337@gmail.com>2013-07-20 00:19:08 -0400
commitaef44255920c18f443af28d100fb06d9699d4895 (patch)
treeb1d72ffc9a0e4f6a009ca16e9e3af2260806c193 /tools/benchmark.php
parent81892ebcdcd2929128c2c320f7de975cab8ed368 (diff)
parentf04566f6d30553560d5a69e25e38de72a60f297c (diff)
merge with vichan-gold
Diffstat (limited to 'tools/benchmark.php')
-rw-r--r--tools/benchmark.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/benchmark.php b/tools/benchmark.php
new file mode 100644
index 00000000..8c97364c
--- /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');
+