Created
February 6, 2015 03:42
-
-
Save markstory/61e97eaaf96fd1092fce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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