preg_match($this->re, $line, $matches); if (count($matches) == 0) { return; } $key = $matches[1]; $this->keys[$key]--; } public function emit() { return $this->keys; } } $regex = "/GET \\/ongoing\\/When\\/\\d\\d\\dx\\/(\\d\\d\\d\\d\\/\\d\\d\\/\\d\\d\\/[^ .]+) /"; $fn = new WideFinderFunction($regex); $clock = new React\EEP\Clock\Wall(0); $win = new React\EEP\Window\Monotonic($fn, $clock); // On emit, log top 10 hits to standard output $win->on('emit', function ($matches) { arsort($matches); $i = 0; foreach (array_slice($matches, 0, 10) as $url => $n) { printf("%d:\t%s with %d hits\n", $i++, $url, $n); } echo "\n\n"; }); $fh; if (file_exists("./data.txt")) { $fh = fopen("data.txt", "r"); } else { echo "Fetching data file\n"; $fh = fopen("http://www.tbray.org/tmp/o10k.ap", "r");
} $fns = array("count" => new React\EEP\Stats\Count(), "sum" => new React\EEP\Stats\Sum(), "min" => new React\EEP\Stats\Min(), "max" => new React\EEP\Stats\Max(), "mean" => new React\EEP\Stats\Mean(), "vars" => new React\EEP\Stats\Variance(), "stdevs" => new React\EEP\Stats\Stdev()); $headers = array("Count\t\t", "Sum\t\t", "Min\t\t", "Max\t\t", "Mean\t\t", "Variance\t", "Stdev\t\t"); // Convenient. But should only be used for composing independant, not related functions $comp_fn = new React\EEP\Composite($fns); $clock = new React\EEP\Clock\Wall(0); $m1 = new React\EEP\Window\Monotonic($comp_fn, $clock); // Correct. The stats functions can be coalesced into a single function. // Faster by 4X $fn = new React\EEP\Stats\All(); $clock = new React\EEP\Clock\Counting(); $m2 = new React\EEP\Window\Monotonic($fn, $clock); // Neither. Faster than m1, but slower than m2. Save some cycles, use m2! $clock = new React\EEP\Clock\Counting(); $fn = new LeStatFunction(); $m3 = new React\EEP\Window\Monotonic($fn, $clock); $m1->on("emit", function ($values) use($headers) { foreach ($values as $i => $v) { echo $headers[$i], "\t\t", $v, "\n"; } }); $m2->on("emit", function ($values) { echo json_encode($values), "\n"; }); $m3->on("emit", function ($values) { echo json_encode($values), "\n"; }); if ($_SERVER['argc'] != 2) { echo "\nUsage: ", $_SERVER['argv'][0], " <items>\n"; exit; }