<?php

function timer($func) {
	$begin = microtime(true);
	$times = 10; // how many times will run

	for ($i = 1; $i <= $times; $i++) {
		$func();
	}

	$total = microtime(true) - $begin;
	return "\n\n Total: ${total} in ${times} times \n";
}


$cli = function(){
	shell_exec("/usr/local/bin/convert /tmp/test.jpg -resize 120x120 /tmp/bacon.jpg");
};

$ext_imagick = function(){
	$i = new Imagick('/tmp/test.jpg');
	$i->scaleImage(120, 120, true);
	$i->writeImage('/tmp/bacon_.jpg');
};

$ext_gmagick = function(){
	$i = new Gmagick('/tmp/test.jpg');
	$i->scaleImage(120, 120, true);
	$i->writeImage('/tmp/bacon_.jpg');
};

echo timer($cli);
echo timer($ext_imagick);
echo timer($ext_gmagick);