Пример #1
0
        $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");
}
while ($line = fgets($fh)) {
    $win->enqueue($line);
}
$win->tick();
fclose($fh);
Пример #2
0
$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;
}
$items = $_SERVER['argv'][1];
$start = microtime(true);
for ($i = 1; $i <= $items; $i++) {
    $m1->enqueue($i);
}
$m1->tick();
$end = microtime(true);
printf("V1. Elapsed: %.2f meps: %.3f\n", $end - $start, $items / ($end - $start) / 1000000.0);
$start = microtime(true);
for ($i = 1; $i <= $items; $i++) {