This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
364 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace ZendBench\EventManager; | ||
|
||
use Zend\EventManager\SharedEventManager; | ||
use Zend\EventManager\EventManager; | ||
use Athletic\AthleticEvent; | ||
|
||
class MultipleEventIndividualSharedListener extends AthleticEvent | ||
{ | ||
use TraitEventBench; | ||
|
||
private $sharedEvents; | ||
|
||
private $events; | ||
|
||
private $eventsToTrigger; | ||
|
||
public function setUp() | ||
{ | ||
$identifiers = $this->getIdentifierList(); | ||
$this->sharedEvents = new SharedEventManager(); | ||
foreach ($this->getEventList() as $event) { | ||
$this->sharedEvents->attach($identifiers[0], $event, $this->generateCallback()); | ||
} | ||
$this->events = new EventManager(); | ||
$this->events->setSharedManager($this->sharedEvents); | ||
$this->events->setIdentifiers([$identifiers[0]]); | ||
|
||
$this->eventsToTrigger = array_filter($this->getEventList(), function ($value) { | ||
return ($value !== '*'); | ||
}); | ||
} | ||
|
||
/** | ||
* Trigger the event list | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function trigger() | ||
{ | ||
foreach ($this->eventsToTrigger as $event) { | ||
$this->events->trigger($event); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace ZendBench\EventManager; | ||
|
||
use Zend\EventManager\EventManager; | ||
use Athletic\AthleticEvent; | ||
|
||
class MultipleEventLocalListener extends AthleticEvent | ||
{ | ||
use TraitEventBench; | ||
|
||
private $eventsToTrigger; | ||
|
||
public function setUp() | ||
{ | ||
$this->events = new EventManager(); | ||
|
||
$this->eventsToTrigger = array_filter($this->getEventList(), function ($value) { | ||
return ($value !== '*'); | ||
}); | ||
} | ||
|
||
/** | ||
* Attach and trigger the event list | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function trigger() | ||
{ | ||
foreach ($this->eventsToTrigger as $event) { | ||
$this->events->attach($event, $this->generateCallback()); | ||
$this->events->trigger($event); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
benchmarks/MultipleEventMultipleLocalAndSharedListener.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace ZendBench\EventManager; | ||
|
||
use Zend\EventManager\SharedEventManager; | ||
use Zend\EventManager\EventManager; | ||
use Athletic\AthleticEvent; | ||
|
||
class MultipleEventMultipleLocalAndSharedListener extends AthleticEvent | ||
{ | ||
use TraitEventBench; | ||
|
||
private $sharedEvents; | ||
|
||
private $events; | ||
|
||
private $eventsToTrigger; | ||
|
||
public function setUp() | ||
{ | ||
$identifiers = $this->getIdentifierList(); | ||
$this->sharedEvents = new SharedEventManager(); | ||
foreach ($this->getIdentifierList() as $identifier) { | ||
foreach ($this->getEventList() as $event) { | ||
$this->sharedEvents->attach($identifier, $event, $this->generateCallback()); | ||
} | ||
} | ||
$this->events = new EventManager(); | ||
$this->events->setSharedManager($this->sharedEvents); | ||
$this->events->setIdentifiers($identifiers); | ||
|
||
$this->eventsToTrigger = array_filter($this->getEventList(), function ($value) { | ||
return ($value !== '*'); | ||
}); | ||
} | ||
|
||
/** | ||
* Attach and trigger the event list | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function trigger() | ||
{ | ||
foreach ($this->eventsToTrigger as $event) { | ||
for ($i = 0; $i < $this->numListeners; $i += 1) { | ||
$this->events->attach($event, $this->generateCallback()); | ||
} | ||
$this->events->trigger($event); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace ZendBench\EventManager; | ||
|
||
use Zend\EventManager\SharedEventManager; | ||
use Zend\EventManager\EventManager; | ||
use Athletic\AthleticEvent; | ||
|
||
class MultipleEventMultipleSharedListener extends AthleticEvent | ||
{ | ||
use TraitEventBench; | ||
|
||
private $sharedEvents; | ||
|
||
private $events; | ||
|
||
private $eventsToTrigger; | ||
|
||
public function setUp() | ||
{ | ||
$identifiers = $this->getIdentifierList(); | ||
$this->sharedEvents = new SharedEventManager(); | ||
foreach ($this->getIdentifierList() as $identifier) { | ||
foreach ($this->getEventList() as $event) { | ||
$this->sharedEvents->attach($identifier, $event, $this->generateCallback()); | ||
} | ||
} | ||
$this->events = new EventManager(); | ||
$this->events->setSharedManager($this->sharedEvents); | ||
$this->events->setIdentifiers($identifiers); | ||
|
||
$this->eventsToTrigger = array_filter($this->getEventList(), function ($value) { | ||
return ($value !== '*'); | ||
}); | ||
} | ||
|
||
/** | ||
* Trigger the event list | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function trigger() | ||
{ | ||
foreach ($this->eventsToTrigger as $event) { | ||
$this->events->trigger($event); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace ZendBench\EventManager; | ||
|
||
use Zend\EventManager\EventManager; | ||
use Athletic\AthleticEvent; | ||
|
||
class SingleEventMultipleListener extends AthleticEvent | ||
{ | ||
use TraitEventBench; | ||
|
||
private $events; | ||
|
||
public function setUp() | ||
{ | ||
$this->events = new EventManager(); | ||
for ($i = 0; $i < $this->numListeners; $i++) { | ||
$this->events->attach('dispatch', $this->generateCallback()); | ||
} | ||
} | ||
|
||
/** | ||
* Trigger the dispatch event | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function trigger() | ||
{ | ||
$this->events->trigger('dispatch'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace ZendBench\EventManager; | ||
|
||
use Zend\EventManager\SharedEventManager; | ||
use Zend\EventManager\EventManager; | ||
use Athletic\AthleticEvent; | ||
|
||
class SingleEventMultipleSharedListener extends AthleticEvent | ||
{ | ||
use TraitEventBench; | ||
|
||
private $sharedEvents; | ||
|
||
private $events; | ||
|
||
public function setUp() | ||
{ | ||
$identifiers = $this->getIdentifierList(); | ||
$this->sharedEvents = new SharedEventManager(); | ||
for ($i = 0; $i < $this->numListeners; $i += 1) { | ||
$this->sharedEvents->attach($identifiers[0], 'dispatch', $this->generateCallback()); | ||
} | ||
$this->events = new EventManager(); | ||
$this->events->setSharedManager($this->sharedEvents); | ||
$this->events->setIdentifiers([$identifiers[0]]); | ||
} | ||
|
||
/** | ||
* Trigger the dispatch event | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function trigger() | ||
{ | ||
$this->events->trigger('dispatch'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace ZendBench\EventManager; | ||
|
||
use Zend\EventManager\EventManager; | ||
use Athletic\AthleticEvent; | ||
|
||
class SingleEventSingleListener extends AthleticEvent | ||
{ | ||
use TraitEventBench; | ||
|
||
private $events; | ||
|
||
public function setUp() | ||
{ | ||
$this->events = new EventManager(); | ||
$this->events->attach('dispatch', $this->generateCallback()); | ||
} | ||
|
||
/** | ||
* Trigger the dispatch event | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function trigger() | ||
{ | ||
$this->events->trigger('dispatch'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace ZendBench\EventManager; | ||
|
||
use Zend\EventManager\SharedEventManager; | ||
use Zend\EventManager\EventManager; | ||
use Athletic\AthleticEvent; | ||
|
||
class SingleEventSingleSharedListener extends AthleticEvent | ||
{ | ||
use TraitEventBench; | ||
|
||
private $sharedEvents; | ||
|
||
private $events; | ||
|
||
public function setUp() | ||
{ | ||
$identifiers = $this->getIdentifierList(); | ||
$this->sharedEvents = new SharedEventManager(); | ||
$this->sharedEvents->attach($identifiers[0], 'dispatch', $this->generateCallback()); | ||
$this->events = new EventManager(); | ||
$this->events->setSharedManager($this->sharedEvents); | ||
$this->events->setIdentifiers([$identifiers[0]]); | ||
} | ||
|
||
/** | ||
* Trigger the dispatch event | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function trigger() | ||
{ | ||
$this->events->trigger('dispatch'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace ZendBench\EventManager; | ||
|
||
trait TraitEventBench | ||
{ | ||
private $numListeners = 50; | ||
|
||
private function generateCallback() | ||
{ | ||
return function ($e) { | ||
}; | ||
} | ||
|
||
private function getEventList() | ||
{ | ||
return [ | ||
'dispatch', | ||
'dispatch.post', | ||
'*', | ||
]; | ||
} | ||
|
||
private function getIdentifierList() | ||
{ | ||
return [ | ||
'Zend\Stdlib\DispatchableInterface', | ||
'Zend\Mvc\Controller\AbstractController', | ||
'Zend\Mvc\Controller\AbstractActionController', | ||
'Zend\Mvc\Controller\AbstractRestfulController', | ||
'ZF\Rest\RestController', | ||
'CustomRestController', | ||
]; | ||
} | ||
} |
This file contains 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