Skip to content

Instantly share code, notes, and snippets.

@markstory
Created February 6, 2015 03:42
Show Gist options
  • Save markstory/61e97eaaf96fd1092fce to your computer and use it in GitHub Desktop.
Save markstory/61e97eaaf96fd1092fce to your computer and use it in GitHub Desktop.
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Event\EventManager;
class EventShell extends Shell
{
public function main()
{
$events = new EventManager();
$start = microtime(true);
foreach (range(1, 20) as $i) {
$events->on('Custom.event', function () {
return true;
});
}
$end = microtime(true);
$this->out(sprintf('Binding 20 local events took: %f', $end-$start));
$start = microtime(true);
foreach (range(1, 20) as $i) {
EventManager::instance()->on('Global.event', function () {
return true;
});
}
$end = microtime(true);
$this->out(sprintf('Binding 20 global events took: %f', $end-$start));
$start = microtime(true);
foreach (range(1, 1000) as $i) {
$events->dispatch('Global.event');
}
$end = microtime(true);
$this->out(sprintf('Dispatching 1000 global events took: %f', $end-$start));
$start = microtime(true);
foreach (range(1, 1000) as $i) {
$events->dispatch('Custom.event');
}
$end = microtime(true);
$this->out(sprintf('Dispatching 1000 local events took: %f', $end-$start));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment