| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | function timer($func) { |
|---|
| 4 | $begin = microtime(true); |
|---|
| 5 | $times = 10; // how many times will run |
|---|
| 6 | |
|---|
| 7 | for ($i = 1; $i <= $times; $i++) { |
|---|
| 8 | $func(); |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | $total = microtime(true) - $begin; |
|---|
| 12 | return "\n\n Total: ${total} in ${times} times \n"; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | $cli = function(){ |
|---|
| 17 | shell_exec("/usr/local/bin/convert /tmp/test.jpg -resize 120x120 /tmp/bacon.jpg"); |
|---|
| 18 | }; |
|---|
| 19 | |
|---|
| 20 | $ext_imagick = function(){ |
|---|
| 21 | $i = new Imagick('/tmp/test.jpg'); |
|---|
| 22 | $i->scaleImage(120, 120, true); |
|---|
| 23 | $i->writeImage('/tmp/bacon_.jpg'); |
|---|
| 24 | }; |
|---|
| 25 | |
|---|
| 26 | $ext_gmagick = function(){ |
|---|
| 27 | $i = new Gmagick('/tmp/test.jpg'); |
|---|
| 28 | $i->scaleImage(120, 120, true); |
|---|
| 29 | $i->writeImage('/tmp/bacon_.jpg'); |
|---|
| 30 | }; |
|---|
| 31 | |
|---|
| 32 | echo timer($cli); |
|---|
| 33 | echo timer($ext_imagick); |
|---|
| 34 | echo timer($ext_gmagick); |
|---|