#!/usr/bin/php */ /* Uses PEAR::Benchmark to time program execution Available from http://pear.php.net/package/Benchmark */ error_reporting(E_ALL); require 'Benchmark/Timer.php'; $timer = new Benchmark_Timer(TRUE); $timer->setMarker('Mark1'); while (1) { $x = rtrim(fgets(STDIN)); if (empty($x)) { break ; } else { $input[] = $x; } } $timer->setMarker('Mark2'); foreach ((array) $input as $val) { if ($val == 0) { break; } fputs(STDOUT, factorial($val) . "\n"); } $timer->setMarker('Mark3'); function factorial($int) { $res = 1; $int = intval($int); while ($int > 0 && $int <= 11) { $res *= $int; $int--; } return $res; } $timer->stop(); fputs(STDOUT, "\n"); ?>